1
votes

I'm currently learning to use the Jenkins build pipeline. I have one pipeline where I archive the artifact of the build like this:

stage("Build") { gitlabCommitStatus(name: "Build") {
    /*Build my program and zip it*/
    archiveArtifacts artifacts: 'Debug.7z', onlyIfSuccessful: true
}}

Now I want to use this artifact in another pipeline, but I can't find a command to download a archived artifact into my new pipeline. Note that I do not want to use the artifact in another stage, but in a completely different pipeline of a different build project.

1

1 Answers

4
votes

You need to have Copy Artifact plugin installed for this to work. In the job where you want to copy the artifact, use the following code:

pipeline {
    stages {
        stage ('Copy Build Artifact') {
            steps {
                echo 'Copying artifact from projectA'
                copyArtifacts(projectName: 'projectA', filter:'Debug.7z', optional: true);
                // OR
                // copyArtifacts(projectName: 'projectA', filter:'Debug.7z', selector: specific('5'), optional: true);
            }
        }
    }
}

where:

selector: the selector to select the build to copy from. If not specified, latest stable build is used

optional: do not fail the step even if no appropriate build is found