Search code examples
jenkinsartifactory

Jenkins wait for artifact download to finish


I am downloading multiple artifacts with Artifactory

rtDownload (
serverId: 'Artifactory-1',
spec: '''{
      "files": [
        {
          "pattern": "bazinga-repo/froggy-files/",
          "target": "bazinga/"
        }
      ]
}''',

// Optional - Associate the downloaded files with the following custom build name and build number,
// as build dependencies.
// If not set, the files will be associated with the default build name and build number (i.e the
// the Jenkins job name and number).
buildName: 'holyFrog',
buildNumber: '42'
)

Which works but this works asynchronously, and I have to use the results as soon as it finished. How do I await for each rtDownload in pipeline syntax?


Solution

  • This code works for me with downloading two artifacts:

    def target = params.BuildInfo.trim()
    
    def downloadSpec = """{
      "files": [{
        "pattern": "${artifactory}.zip",
        "target": "./${target}.zip"
      }]
    }"""
    
    def buildInfo = server.download spec: downloadSpec
    def files = findFiles(glob: "**/${target}.zip") // Define `files` here
    
    if (files) { // And verify `it` here, so it'll wait 
    ...
    }