0

Extended Choice Parameter plugin query: How to load params dynamically from a JSON file for jenkins build job. Here is my jenkins script to add normal parameters and Extended Choice parameters as well.

p

roperties([
        [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '500']],
        parameters([extendedChoice( 
        defaultValue: 'One,Two,Three,Four', 
        description: '', 
        multiSelectDelimiter: ',', 
        name: 'SAMPLE_EXTENDED_CHOICE', 
        quoteValue: false, 
        saveJSONParameterToFile: false, 
        type: 'PT_CHECKBOX', 
        value:'One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten', 
        visibleItemCount: 10)
        ])
])

This is working. But I want to be able to load parameters from a JSON file (using Extended Choice Parameter plugin). How can I modify the above script to accomplish that? PS: Here is the reference for Extended Parameter plugin. https://plugins.jenkins.io/extended-choice-parameter/

1

EDIT: Updating my answer to include steps on using the Declarative Directive Generator.

You can experiment with the different available configuration options, and sometimes gets hints as to what certain settings provide. For this specific case:

  1. Navigate to <$JENKINS_URL>/directive-generator/
  2. Select parameters: Parameters from the Sample Directive drop-down.
  3. Click the Add button and select extendedChoice: Extended Choice Parameter
  4. Select JSON Parameter Type and then experiment with the available options.
  5. When finished, click Generate Declarative Directive to generate the code block to paste into your pipeline.

Using the Declarative Directive Generator

You can add the javascriptFile parameter and change the type to PT_JSON.

Using your example:

properties([
    [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '500']],
    parameters([extendedChoice( 
    defaultValue: 'One,Two,Three,Four', 
    description: '', 
    javascriptFile: '/path/to/file.json',
    multiSelectDelimiter: ',', 
    name: 'SAMPLE_EXTENDED_CHOICE', 
    quoteValue: false, 
    saveJSONParameterToFile: false, 
    type: 'PT_JSON', 
    value:'One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten', 
    visibleItemCount: 10)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.