Pipeline Snippet Generator return the name of the object instead of the object with the parameters

Article ID:115003891391
1 minute readKnowledge base

Issue

Pipeline Snippet Generator returns the name of the object in angle brackets instead of the valid Pipeline code

Environment

  • CloudBees Jenkins Enterprise - Managed controller (CJE-MM)

Resolution

For some plugins when you use the "Snippet Generator" for Pipelines you could obtain the name of the object instead of the parameter with all the values that you have previously filled.

Let see an example:

If you choose "input" and choose the "Extended Choice Parameter" option:

Choose Extended Choice Parameter

and fill all the fields:

Fill all fields

When you click on "Generate Pipeline Script" you obtain something like that:

Result

When you should obtain the script needed to generate the fields that you have previously generated.

This is because the plugin is not correctly integrated with the Snippet Pipeline Script.

In these cases, you should create manually a new object of that type.

In order to obtain that you should follow these steps:

  1. Go to the Javadoc of the plugin or to the GitHub class and look for a constructor method for the object that you need:

  2. Add an import of that class in your pipeline:

     import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
  3. From the constructor method create a variable in pipeline that get the result of the constructor:

     def multiSelect= new ExtendedChoiceParameterDefinition("name",
                 "PT_MULTI_SELECT",
                 "blue,green,yellow,blue",
                 "project name",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "blue,green,yellow,blue",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 "",
                 false,
                 false,
                 3,
                 "multiselect",
                 ",")
  4. And substitute the object with [variable]:

        def userInput = input  id: 'customID', message: 'Let\'s promote?', ok: 'Release!', parameters:  [multiSelect]