问题描述
在Jenkins Pipeline中,如何将工件从先前的版本复制到当前的版本?即使以前的构建失败,我也想这样做.
In Jenkins Pipeline, how can I copy the artifacts from a previous build to the current build?I want to do this even if the previous build failed.
推荐答案
Stuart Rowe 也向我推荐了我查看了复制工件插件的管道创作Sig Gitter频道还给了我一些示例要使用的詹金斯管道语法.
Stuart Rowe also recommended to me on the Pipeline Authoring Sig Gitter channel that I look at the Copy Artifact Plugin, but also gave me some sample Jenkins Pipeline syntax to use.
根据他的建议,我想到了这个更完整的Pipeline示例它将工件从先前的版本复制到当前的版本,以前的构建是成功还是失败.
Based on the advice that he gave, I came up with this fuller Pipeline examplewhich copies the artifacts from the previous build into the current build,whether the previous build succeeded or failed.
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")
}
}
}
}
这篇关于Jenkins管道,如何将工件从先前的版本复制到当前的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!