问题
I'm trying to solve the same problem as this SO question: How to trigger a jenkins build on specific node using pipeline plugin?
The only difference in my case is that the job I'm triggering is another scripted pipeline job. So the second step in the proposed solution does not apply in my case:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- In pipeline script, use code (code omitted)
My question is how to define the :
org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition
parameter inside my scripted pipeline parameterized job (not through the GUI).
What I have tried:
properties([[$class : 'RebuildSettings',
autoRebuild : false,
rebuildDisabled: false],
parameters([org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition(name: 'node')])])
回答1:
The easiest way to generate the code you need for your parameterized scripted pipeline is to:
- Go to Pipeline Snippet Generator
- Select "properties: Set job properties"
- Check "This project is parameterized"
- Click "Add parameter" and select "Label"
- Click "Generate pipeline script"
This gives you:
properties([
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters([
[$class: 'LabelParameterDefinition',
allNodesMatchingLabel: false,
defaultValue: '',
description: '',
name: 'node',
nodeEligibility: [$class: 'AllNodeEligibility'], t
riggerIfResult: 'allCases']
]
)
])
But in my case this wasn't even necessary. All you need is a regular string parameter with a custom name, lets say "node" and then do:
node(params.node){}
来源:https://stackoverflow.com/questions/55470917/how-to-define-a-label-parameter-in-a-parameterized-build-using-scripted-pipeline