在Jenkins Pipeline中,如何将工件从先前的版本复制到当前的版本? 即使以前的构建失败,我也想这样做。
答案 0 :(得分:2)
Stuart Rowe在Pipeline Authoring Sig Gitter channel上还向我推荐了我查看“复制工件”插件,但也给了我一些示例Jenkins Pipeline syntax to use。
根据他的建议,我想到了这个更完整的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")
}
}
}
}
答案 1 :(得分:0)
答案 2 :(得分:0)
假设您希望以前的版本中包含单个文件,甚至可以在mvn调用之前使用curl将文件放置在工作区中。
stage('Copy csv') {
steps {
sh "mkdir -p ${env.WORKSPACE}/dump"
sh "curl http://<jenkins-url>:<port>/job/<job-folder>/job/<job-name>/job/<release>/lastSuccessfulBuild/artifact/dump/sample.csv/*view*/ -o ${env.WORKSPACE}/dump/sample.csv"
}
}
谢谢, 灰烬