I'm using in Jenkins 2.73.1, in a multibranch pipeline Copy Artifact Plugin to get the last successful artifacts from two other pipelines, see my 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'])
})
}
}
}
}
}
In the build log I see e.g.:
...
[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
...
Question / Goal: I'd like to parse and save to a file (to be archived, then loaded and parsed by groovy in a different pipeline) the build number of frontend and backend (in the log see "build number 17" and "build number 3").
In the question Jenkins Pipeline - Reading previous stage log I read it's possible to redirect the standard output of an sh script into a groovy variable, like this:
def out = sh script: 'command', returnStdout: true
But in my pipeline I need to use windows, also the step in this case is not a command but it's a "step" (containing class "CopyArtifact", still new to Jenkins, I just made it work googling around and found some examples using this syntax).
How can I achieve my goal? Should I parse the entire log in this case or is there a more elegant solution? Please provide some code in your answer, so I can test it directly.