Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 570
DenCowboy Avatar asked Sep 18 '18 13:09

DenCowboy


1 Answers

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).

like image 86
Michael Avatar answered Nov 10 '22 14:11

Michael