Jenkins pipeline share information between jobs

前端 未结 3 705
渐次进展
渐次进展 2021-01-20 21:40

We are trying to define a set of jobs on Jenkins that will do really specific actions. JobA1 will build maven project, while JobA2 will build .NET code, JobB will upload it

3条回答
  •  孤城傲影
    2021-01-20 22:01

    There are two ways to share info between jobs:

    1. You can use stash/unstash to share the files/data between multiple jobs in a single pipeline.

      stage ('HostJob') {
          build 'HostJob'
          dir('/var/lib/jenkins/jobs/Hostjob/workspace/') {
              sh 'pwd'
              stash includes: '**/build/fiblib-test', name: 'app' 
          }
      }
      
      stage ('TargetJob') {
          dir("/var/lib/jenkins/jobs/TargetJob/workspace/") {
          unstash 'app'
          build 'Targetjob'
      }
      

      In this manner, you can always copy the file/exe/data from one job to the other. This feature in pipeline plugin is better than Artifact as it saves only the data locally. The artifact is deleted after a build (helps in data management).

    2. You can also use Copy Artifact Plugin.

      There are two things to consider for copying an artifact:

      a) Archive the artifacts in the host project and assign permissions.

      b) After building a new job, select the 'Permission to copy artifact' → Projects to allow copy artifacts: *

      c) Create a Post-build Action → Archive the artifacts → Files to archive: "select your files"

      d) Copy the artifacts required from host to target project. Create a Build action → Copy artifacts from another project → Enter the ' $Project name - Host project', which build 'e.g. Lastest successful build', Artifacts to copy '$host project folder', Target directory '$localfolder location'.

提交回复
热议问题