Dynamic parameter in a Jenkins file?

How can I use the Jenkins dynamic plugin in Jenkinsfile ?

I am looking for a Jenkinsfile fragment that:

  • Enables the Build with Parameters in the Jenkins job
  • If selected, a script is populated that populates the list that Dynamic Choice Parameters can use, and the user will see a drop-down list.

Upon attempt:

  • Pipeline syntax in Jenkins editor
  • Choosing properties: Set job properties as Sample step
  • Choosing This project is parameterized
  • Using Dynamic Choice Parameter
  • Enter values ​​for Name , Choice Script , Remote Script , etc.
  • Generate Pipeline Script

I get the following pattern:

 properties([ parameters([ <object of type com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition> ]), pipelineTriggers([]) ]) 

i.e. the generated script pipeline does not contain the data that I entered in step 5. above. How to change parameters so that parameter name, selection, etc. Were visible to the user?


Jenkins version: 2.19.3 Dynamic parameter version: 0.2.0

+6
source share
1 answer

no longer needed for a Jenkins dynamic plugin. Just use the standard selection or string parameter and update the value (s) with the groovy code.

 #!/bin/groovy def envs = loadEnvs(); properties([ parameters([ choice(choices: envs, description: 'Please select an environment', name: 'Env') ]) ]) node { try { stage('Preparation'){ ... 

If you use a selection parameter, you should specify a string in which the values ​​are separated by a new string.

For instance:

 "a\nb\nc" 

If you really need a plugin, vote on this JENKINS-42149 .

+3
source

Source: https://habr.com/ru/post/1012577/


All Articles