Hi,
I'm trying to find documentation on how global variables in a Jenkinsfile
work. I've found bits and pieces, but not a single authoritative location
on the programming model.
Any pointers?
In particular, I've managed to get the following code(paraphrased from our
project) to work by googling, trial and error, but I'd like to understand
the underlying rules or I fear that my code will break at any moment and I
won't have a clue why.
The snippet below is intended to collect information about the build in a
map that I transform to JSON and email to our mailing list.
// What's this 'Field' thing and why do I need it? What does it mean to
leave it out? Sometimes I want global variables
// to be visible to all nodes, other times I want changes to be local to
the node.
@Field
// Eclipse Groovy IDE will indent 'def buildInfo' below, I think Eclipse is
trying to tell me something, but I don't know what.
def buildInfo
// I have to put assignment of global variables on a separate line,
otherwise they don't always work
buildInfo = [:]
// If we don't make it to the end
buildInfo['success'] = false
def setupbuilds() {
node('master') {
// We need to do a bit of work on a real node in order to find out what
builds we need to run.
builds = [somebuild: stage('foo') {
buildInfo['blah'] = 123
if (buildInfo['moreblah']) {
// This could be interesting.... Race conditions?
}
},
somebuild: stage('foo') {
// amazingly this works! How does the information flow
from
// the node back to the flywheel executor? How are
partial updates to a
// map implemented?
buildInfo['moreblah'] = 123
if (buildInfo['blah']) {
// This could be interesting.... Race conditions?
}
}]
}
}
try {
setupbuild()
parallel builds
buildInfo['success'] = true
} finally {
// Here I can email buildInfo to our mailing list and we're going to put
together some code that is going to format it nicely
}
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/9b835650-8302-4a08-89d3-8ae65c0da8cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.