Created
May 29, 2018 15:26
-
-
Save tamasgal/e520784a2e58ea4a3300f9c0e3cfa323 to your computer and use it in GitHub Desktop.
Getting a list of filenames in a given directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
import static groovy.io.FileType.FILES | |
node('master') { | |
FILES_DIR = './foo' | |
cleanWs() | |
sh """ | |
mkdir foo | |
touch foo/bar1 | |
touch foo/bar2 | |
touch foo/bar3 | |
""" | |
def filenames = []; | |
def dir = new File("${env.WORKSPACE}/${FILES_DIR}"); | |
dir.traverse(type: FILES, maxDepth: 0) { | |
filenames.add(it.getName()) | |
} | |
for (int i = 0; i < filenames.size(); i++) { | |
def filename = filenames[i] | |
echo "${filename}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, this one works. Ridiculous...