Last active
September 23, 2019 12:19
-
-
Save f-steff/df96a6f7f8ae54de9a437c01982f7956 to your computer and use it in GitHub Desktop.
Jenkins Groovy: List folders located in a particular FTP folder.
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
// Created by f-steff 2019. Use and abuse as you wish. | |
@Grab(group='commons-net', module='commons-net', version='2.0') | |
import org.apache.commons.net.ftp.FTPClient | |
import org.apache.commons.net.ftp.FTPFile | |
//def path="pub/" | |
println("Fetching reverse sorted list of ftp folders from $path"); | |
FTPClient ftpClient = new FTPClient() | |
ftpClient.connect "arnold.c64.org",21 | |
ftpClient.enterLocalPassiveMode() | |
ftpClient.login "anonymous", "[email protected]" | |
ftpClient.changeWorkingDirectory(path) | |
FTPFile[] entries = ftpClient.listDirectories().sort { it.getTimestamp().getTime() }.reverse() | |
def BuildMap = [:] | |
for (FTPFile directory : entries) { | |
BuildMap.put(path+directory.getName(),directory.getName() ) | |
} | |
ftpClient.logout() | |
ftpClient.disconnect() | |
println("Done!"); | |
BuildMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List folders loacted in a particular FTP folder.
Used by Jenkins using the Active Choices Parameter plugin
FTP URL and port, as well as username and password are hardcoded in the script.
FTP path needs to be supplied in a variable.
Instructions for uploading the script.
Instructions for using the script.
When run access the selected value through the ${MySelectedFolder} variable