Aleks G
Aleks G

Reputation: 57316

Jenkins artifactory plugin - identify that files are not there

I'm using Jenkins Artifactory plugin to publish artifacts as well as download required artifacts. When downloading artifacts, what needs to be downloaded is determined dynamically while the Jenkins pipeline is executing.

If the artifacts that need to be downloaded are not there in artifactory, I want to abort the pipeline with a corresponding error message. Unfortunately, I can't figure out how to determine presence or absence of files. Artifactory.download call does not throw any exceptions if requested files are not there and doesn't return any meaningful information.

Of course, I can always check whether or not files exist after the download, but I was hoping for some "native" way. So, how can I verify after the download call whether or not my requested artifacts have been downloaded?

Upvotes: 1

Views: 1798

Answers (1)

yahavi
yahavi

Reputation: 6043

Actually, there are 2 options:

Option 1: Use the failNoOp flag. It'll fail your pipeline in case of 0 downloads:

server.download spec: downloadSpec, failNoOp: true

Option 2: In the latest Jenkins Artifactory plugin v3.2.0 there is a new feature to list downloaded/uploaded files:

def buildInfo = Artifactory.newBuildInfo()
server.download spec: downloadSpec, buildInfo: buildInfo
if (buildInfo.getDependencies().size() == 0) {
 // Do your magic
}

More information can be found in the documentation.

Upvotes: 8

Related Questions