在Jenkins Pipeline中,如何将工件从先前的版本复制到当前的版本?即使以前的构建失败,我也想这样做。
Stuart Rowe还在管道制作Sig Gitter频道上向我推荐了我查看“复制工件插件”的方法,但也给了我一些要使用的Jenkins Pipeline语法示例。
根据他给出的建议,我想到了一个更完整的Pipeline示例,该示例将工件从先前的构建复制到当前的构建中,而不管先前的构建是成功还是失败。
pipeline { agent any; stages { stage("Zeroth stage") { steps { script { if (currentBuild.previousBuild) { try { copyArtifacts(projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")) def previousFile = readFile(file: "usefulfile.txt") echo("The current build is ${currentBuild.number}") echo("The previous build artifact was: ${previousFile}") } catch(err) { // ignore error } } } } } stage("First stage") { steps { echo("Hello") writeFile(file: "usefulfile.txt", text: "This file ${env.BUILD_NUMBER} is useful, need to archive it.") archiveArtifacts(artifacts: 'usefulfile.txt') } } stage("Error") { steps { error("Failed") } } } }