Hello, I am at wit's end trying to make Jenkins run a freestyle job build
on a node based on a Label parameter I set using a Groovy script in the
job, rather than the value provided by the user who started the build.
I will be deeply grateful for (a link to) a working example. Below are
things I have tried which do not work.
I am using the same Groovy script everywhere, so I will post it first
(noting that in some contexts, I replace build with currentBuild):
def map = build.getBuildVariables()
if (map.XcodeVersion ==~ /^12\..*$/) { map.Label = map.Label + ' &&
xcode12' }
return map
I have tried the Environment Injector plugin's “Prepare an environment for
the run” *with* the Override Build Parameters checkbox checked. I have
tried “Run buildstep before SCM runs”. I have tried “Execute system Groovy
script”. In none of these cases have I checked the sandbox script option.
And, in none of the cases does Jenkins use the new Label expression to
decide where to run the build.
I understand that I could trigger a downstream build, etc., but those
workarounds each have their downsides. I also would like to avoid telling
people that they have to remember to use boolean label expressions like unity
&& xcode12 when they start a build.
If any developers are reading this, I feel Jenkins is peculiarly inflexible
about label/node selection. For example, it is not possible to pass a
parameter $FOO to the “Restrict where this project can be run” field. Nor
is it possible to define labels which expand to a label expression.
Depending on people to remember boolean expressions to use is not really
good UX.
If I am going about this all wrong, none of my Google searches on the topic
have hinted at the right way to do it, except perhaps for Pipeline, which
would not be my first choice of a solution, given its intrusiveness. Thank
you for reading to the end and I hope someone can help me out. David
--
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/3a82a693-2f26-491b-ac88-d57bcead56c3n%40googlegroups.com.