问题
I'm currently trying to trigger an existing job and take in the generated artifacts in the current job's workspace.
The following works fine:
pipeline {
agent {
label 'builder-rpm'
}
options {
timestamps()
ansiColor('xterm')
}
stages {
stage('Build Other pipeline') {
steps {
build job: 'Components/components-rpm-build', parameters: [
string(name: 'Component', value: 'foo'),
]
copyArtifacts(
filter: 'results/*.rpm',
fingerprintArtifacts: true,
flatten: true,
projectName: 'Components/components-rpm-build',
selector: lastSuccessful(),
target: "${env.WORKSPACE}/dist"
)
}
}
}
}
The problem of it is that lastSuccessful()
will take indeed the last
successful build, meaning that if some other user manages to run a parallel
build faster than me, I'm going to take in their artifacts instead of mine.
According to this page
there should be a way to use a specific job, with specific
:
def built = build('downstream');
copyArtifacts(projectName: 'downstream',
selector: specific("${downstream.number}"));
There's however no explanation nor example on how to use it in a declarative pipeline.
Any hint?
Thanks in advance for any help.
回答1:
I found some decent solution: switching to script
simply does the job.
pipeline {
agent {
label 'builder-rpm'
}
options {
timestamps()
ansiColor('xterm')
}
stages {
stage('Build Other pipeline') {
steps {
script {
def built = build(
job:'Components/components-rpm-build',
parameters:[
string(name:'Component', value:'ew-filesystem'),
string(name:'RepoServer', value:'')
]
)
copyArtifacts(
projectName: 'Components/components-rpm-build',
selector: specific("${built.number}"),
target: "${env.WORKSPACE}/dist",
filter: "results/*"
)
}
}
}
}
}
来源:https://stackoverflow.com/questions/49030754/declarative-jenkins-pipeline-retrieve-artifact