You might investigate the Node and Label Parameters plugin 
<https://plugins.jenkins.io/nodelabelparameter/>.  I don't know that it 
allows Groovy script evaluation to select the label or node, but it does 
have many options for node and label usage with Freestyle jobs.

On Friday, April 16, 2021 at 4:35:17 PM UTC-6 david...@sciplay.com wrote:

> 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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/86aea44c-dbff-4f80-b260-f5d4c5ad0a2en%40googlegroups.com.

Reply via email to