Hello I am beginner in Groovy/Jenkins/JobDSL.
My question is about applying copyArtifact to the results of just finished downstream jobs.
Question is whether lastCompleted() is reliable or not in order to guarantee that I got artifacts
for this specific build. There can be many builds of job A running in parallel and is important that
we get artifacts from the right one.
Unfortunately the legacy code I have to work with does not call JobSDL primitives directly.
Instead there is a local groovy-class API that makes things harder to explain.
There is job A that runs these two Groovy “statements”
buildStep.downstreamParameterized(‘shaGetterJob’)
buildStep.copyArtifacts(‘shaGetterJob’, ‘’, ‘’, false, {lastCompleted()})
The shaGetterJob contains some steps and
publisher.archiveArtifacts(“VisionCore/detectedGitSHAs.csv”, true)
at the end.
public BuildStep downstreamParameterized(projects, Closure parametersClosure = null, Boolean blocking = true,
Boolean failfast = true, Closure parameterFactoriesClosure = null) {
job.steps {
downstreamParameterized {
trigger(projects) {
if (blocking) {
block {
if (failfast) {
buildStepFailure 'FAILURE'
}
else {
buildStepFailure 'never'
}
failure 'FAILURE'
unstable 'UNSTABLE'
}
}
parameters(parametersClosure)
parameterFactories(parameterFactoriesClosure)
}
}
}
return this
}
public BuildStep copyArtifacts(String jobName,
String includeGlob,
String targetPath = '',
Boolean flattenFiles = true,
Closure copyArtifactsClosure = {latestSuccessful()},
String excludeGlob = '')
leads to
params = [
targetPath: '',
flattenFiles: true,
copyArtifactsClosure: {latestSuccessful()},
conditionalCommand: null,
actionIfFailed: 'DontRun',
parameterFilters: '',
optional: false,
excludeGlob: ''] << params
job.steps {
copyArtifacts(jobName) {
includePatterns includeGlob
targetDirectory params.targetPath
flatten params.flattenFiles
buildSelector params.copyArtifactsClosure
parameterFilters params.parameterFilters
optional params.optional
}
}
public Publisher archiveArtifacts(patternString, allowEmptyArtifact=false,
patternExclude="", ifSuccessful=false) {
job.publishers {
archiveArtifacts {
pattern patternString
allowEmpty allowEmptyArtifact
exclude(patternExclude)
onlyIfSuccessful(ifSuccessful)
}
}
return this
}
