Search code examples
jenkinsjenkins-pipeline

Jenkins - Getting artifacts from child job to parent using Copy Artifact plugin


I am trying to perform the below:

  1. Start Job1
  2. Job1 invokes Job2
  3. Job2 runs and archives artifacts
  4. Job1 continues with other steps after Job2 completes.
  5. Retrieve artifacts from Job2 and use it for other purposes

Is there a way to do #5 here? I did look around but didnt find anything specific. Would CopyArtifact plugin help? If yes, what would be the syntax for pipeline? And how to specify the Identifier of the job which was invoked from Job1 instead of getting "LastSuccessfulBuild" ?

Thanks in advance for looking at this question.


Solution

  • You could use the copyArtifact step like this:

    step([
        $class: 'CopyArtifact', 
        filter: 'myArtifact', 
        projectName: 'Job2', 
        selector: [$class: 'MultiJobBuildSelector']
    ])
    

    You can see the detailed syntax in you Jenkins snippet generator: http://my.Jenkins.com/pipeline-syntax/