开发者

Pulling a file from another job before building in Jenkins?

开发者 https://www.devze.com 2023-04-02 15:26 出处:网络
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 bu

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.


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:

Pulling a file from another job before building in Jenkins?

Jenkins Job Setup for Artifact User Project:

Pulling a file from another job before building in Jenkins?


In your Template job, you can archive the template.xml file as an artifact, then it will be available to your other jobs at a URL similar to the following:

http://myserver/jenkins/job/myjob/lastSuccessfulBuild/artifact/template.xml


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

    }
  }
}


In my end I use a pretty strainghforward approach. I run jenkins in a usual layout (ubuntu 16.04 server) and I need call the checkstyle maven plugin using the same checkstyle.xml config file residing inside a dev-resources job:

Pulling a file from another job before building in Jenkins?

Than I call mvn checkstyle:

Pulling a file from another job before building in Jenkins?

Hope it can be useful for someone else.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号