DenCowboy
DenCowboy

Reputation: 15116

Jenkins pipeline: how to download a archived artifact in a later stage in a Jenkins pipeline

I have a Jenkins pipeline.

In stage A, I have a step in which I need to archive or to save my artifacts because I need to reuse those in a different stage on a different slave:

    stage('Save artifacts'){
        steps {
            archiveArtifacts artifacts: '**/**/target/app*.ear'
        }
    }

Archiving seems to work. I see the artifacts in the UI when the build finishes and can download them. But how can I access/download these artifacts in a later stage?

Upvotes: 9

Views: 9494

Answers (2)

vishun
vishun

Reputation: 97

you can get artifact in this path: $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/archive/xxxx/appxx.ear

Upvotes: 0

Michael
Michael

Reputation: 2683

Instead of archiveArtifacts you should use stash and unstash. E.g.:

stage("Build") {
    steps {
        // ...
        stash(name: "ear", includes: '**/**/target/app*.ear')
    }
}

stage("Deploy") {
    steps {
        unstash("ear")
        // ...
    }
}

Not that stash does not only stash the files, but also their paths. So unstash will put the files exactly in the same places they were (e.g. my-service/target/app.ear).

Upvotes: 7

Related Questions