Stuart Rowe还在Pipeline Authging Sig Gitter频道上向我推荐了Copy Artiect插件,但也给了我一些JenkinsPipeline语法的示例。
根据他给出的建议,我想出了这个更完整的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")
}
}
}
}
假设您希望从以前的构建中获取单个文件,您甚至可以在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"
}
}
谢了阿希什
您可以使用复制工件插件
如需配置,请访问https://wiki.jenkins.io/display/JENKINS/Copy神器插件