Jenkins将工件从上游作业复制到下游作业并返回

bnl4lu3b  于 2023-01-16  发布在  Jenkins
关注(0)|答案(1)|浏览(172)

我的作业A调用了另一个作业B
作业B知道从作业A复制工件。
如何将另一个工件从作业B复制回作业A?

Job A
//////////

 stage('Validation'){
                'Binary Scan':{
                    build job: 'JOB_B'
                },    
           )
        }

Job B 
/////////

stage('Copy Artifacts from Job A'){

copyArtifacts filter: 'testz.zip', 
fingerprintArtifacts: true,
projectName: currentBuild.upstreamBuilds[0].fullProjectName,
selector: upstream()

}

stage('Do something'){
}

stage('Copy Artifacts back to Job A'){

/////?????????
}
7jmck4yq

7jmck4yq1#

在一个项目中,通常不能在另一个项目中执行任意代码。
您可以做的是让作业B使用archiveArtifacts,当它完成时,调用作业(作业A)可以从它触发的作业B的示例中检索对象。build命令将返回一个作业“句柄”,该句柄具有足够的信息,可以让您构建一个copyArtifacts命令。

job A
//////////

stage('Produce artifacts'){
     // First, produce some artifacts for Job B and archive them so that they are available to Job B
     archiveArtifacts artifacts: "testz.zip"
}

stage('Validation'){
     // Invoke Job B (blocks until job B completes)
     def jobB = build job: "JOB_B"

     // Retrieve artifacts from Job B after it completes
     final String artifactsFilter = "build/*.csv"
     copyArtifacts filter: artifactsFilter, projectName: "JOB_B", selector: specific("${jobB.number}")
     // re-attach the same artifacts to Job A (now that they have been copied back into Job A workspace)
     archiveArtifacts artifacts: artifactsFilter
}

Job B 
/////////

stage('Copy Artifacts from Job A'){
    copyArtifacts filter: 'testz.zip', fingerprintArtifacts: true,
                projectName: currentBuild.upstreamBuilds[0].fullProjectName,
                selector: upstream()
}
stage('Do something'){
}
stage('Archive Artifacts for Job A'){
    // Archive desired artifacts
    archiveArtifacts artifacts: "build/**.csv"
}

相关问题