gpt4 book ai didi

Jenkins 管道,如何将工件从以前的构建复制到当前构建?

转载 作者:行者123 更新时间:2023-12-03 18:40:53 29 4
gpt4 key购买 nike

在 Jenkins Pipeline 中,如何将工件从以前的构建复制到当前构建?
即使之前的构建失败,我也想这样做。

最佳答案

Stuart Rowe 还在 Pipeline Authoring Sig Gitter channel 上向我推荐了我查看 Copy Artifact Plugin,但也给了我一些示例 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")
}
}
}
}

关于Jenkins 管道,如何将工件从以前的构建复制到当前构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54382949/

29 4 0
文章推荐: amazon-web-services - Terraform - 为变量指定多个可能的值
文章推荐: R 如何在数据框中获取行的中位数
文章推荐: nodemailer 因连接被拒绝而失败,使用已知良好的 SMTP 服务器
文章推荐: reactjs - 未捕获的类型错误 : Cannot assign to read only property '' of object '#'