Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling a file from another job before building in Jenkins?

Tags:

jenkins

hudson

Hope you can help me on this one. I have a job called "Template" that generates a template.xml file. I have several other jobs that use this template.xml file. However, before they build, i wanted that they could pull the latest template.xml from the "Template" job workspace.

like image 236
Marx Avatar asked Sep 02 '11 14:09

Marx


People also ask

How do you trigger Jenkins job from another Jenkins job with parameters?

You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.


2 Answers

I used Copy Artifacts plugin with Jenkinsfile. Here an example:

In the job that is producing the artifact you should do something like:

pipeline {
 options {
  copyArtifactPermission ‘*’ //Here you can specify the job name also
}
  stages {
    stage(“Run") {
      ...
      archiveArtifacts artifacts: “my_artifact.yaml"
    }
  }
}

In the job that is consuming the artifact you can use something like:

stage("Consumer") {
  steps {
    script {
        copyArtifacts filter: “my_artifact.yaml", projectName: 'PRODUCER_JOB', 
          selector: lastSuccessful()

    }
  }
}
like image 177
Fernanda Martins Avatar answered Oct 05 '22 01:10

Fernanda Martins


In your "template" job, under Post-Build Actions, choose to artifact your xml file using the archive option.

You can then use the "Copy Artifact Plugin" to copy it over to all other jobs.

Jenkins Job Setup for Artifact Generator Project: enter image description here

Jenkins Job Setup for Artifact User Project: enter image description here

like image 45
Sagar Avatar answered Oct 05 '22 00:10

Sagar