【发布时间】:2017-10-06 08:04:50
【问题描述】:
我在 Jenkins 2.73.1 中使用多分支管道 Copy Artifact Plugin 从其他两个管道获取最后成功的工件,请参阅我的 Jenkinsfile:
def branchname = "${BRANCH_NAME}".replace("/", "%2F")
pipeline {
agent {
label 'windows'
}
stages {
stage('get artifacts') {
steps {
script {
parallel('get-backend': {
step([$class: 'CopyArtifact', projectName: "backend/${branchname}", target: 'input/backend'])
},
'get-frontend': {
step([$class: 'CopyArtifact', projectName: "frontend/${branchname}", target: 'input/frontend'])
})
}
}
}
}
}
在构建日志中我看到例如:
...
[Pipeline] script
[Pipeline] {
[Pipeline] parallel
[Pipeline] [get-backend] { (Branch: get-backend)
[Pipeline] [get-frontend] { (Branch: get-frontend)
[Pipeline] [get-backend] step
[Pipeline] [get-frontend] step
[get-frontend] Copied 344 artifacts from "frontend » foo/bar" build number 17
[Pipeline] [get-frontend] }
[get-backend] Copied 2'287 artifacts from "backend » foo/bar" build number 3
[Pipeline] [get-backend] }
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // script
...
问题/目标:我想将前端和后端的内部版本号(在日志见“内部版本号 17”和“内部版本号 3”)。
在Jenkins Pipeline - Reading previous stage log 的问题中,我读到可以将 sh 脚本的标准输出重定向到 groovy 变量中,如下所示:
def out = sh script: 'command', returnStdout: true
但是在我的管道中我需要使用 windows,在这种情况下,步骤也不是命令,而是一个“步骤”(包含类“CopyArtifact”,对于 Jenkins 来说还是新的,我只是让它工作谷歌搜索并发现一些使用这种语法的例子)。
我怎样才能实现我的目标?在这种情况下我应该解析整个日志还是有更优雅的解决方案?请在您的答案中提供一些代码,以便我直接测试。
【问题讨论】:
标签: jenkins jenkins-plugins jenkins-pipeline