Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-26143

Workflow Snippet Generator - Incorrect format for Input with Choice Parameter

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core

      Snippet generator generates an array:

      input id: 'Cc2a7d4d888ad098e3ca0ed7599d887d', message: 'Which environment?', ok: 'Submit', parameters: [[$class: 'ChoiceParameterDefinition', choices: ['Red', 'Blue', 'Green'], description: '', name: 'env']]
      

      ChoiceParameterDefinition requires a delimited string.

      Workaround by modifying the snippet code by converting array to string with "\n" separator, e.g.:

      input id: 'Cc2a7d4d888ad098e3ca0ed7599d887d', message: 'Which environment?', ok: 'Submit', parameters: [[$class: 'ChoiceParameterDefinition', choices: 'Red\nBlue\nGreen', description: '', name: 'env']]
      
      

      Or just join the Array elements:

      input id: 'Cc2a7d4d888ad098e3ca0ed7599d887d', message: 'Which environment?', ok: 'Submit', parameters: [[$class: 'ChoiceParameterDefinition', choices: ['Red', 'Blue', 'Green'].join('\n'), description: '', name: 'env']]
      

          [JENKINS-26143] Workflow Snippet Generator - Incorrect format for Input with Choice Parameter

          Nigel Harniman created issue -

          Jesse Glick added a comment -

          The bug is really in core: the @DataBoundConstructor parameter type does not match the type of the getter.

          The easiest fix would be to rename the constructor parameter to choicesText, which already has a getter. But this forces a workflow to use the ugly syntax.

          Better would be to change the constructor parameter to be List<String>. Requires some mucking around with the config.jelly, perhaps by switching to an actual list control; or by overriding configure(StaplerRequest, JSONObject) in the descriptor to replace choices with choicesText.

          Jesse Glick added a comment - The bug is really in core: the @DataBoundConstructor parameter type does not match the type of the getter. The easiest fix would be to rename the constructor parameter to choicesText , which already has a getter. But this forces a workflow to use the ugly syntax. Better would be to change the constructor parameter to be List<String> . Requires some mucking around with the config.jelly , perhaps by switching to an actual list control; or by overriding configure(StaplerRequest, JSONObject) in the descriptor to replace choices with choicesText .
          Jesse Glick made changes -
          Component/s New: core [ 15593 ]
          Component/s Original: workflow-plugin [ 18820 ]
          Assignee Original: Jesse Glick [ jglick ]
          Labels New: workflow
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-26093 [ JENKINS-26093 ]
          Jesse Glick made changes -
          Link Original: This issue is related to JENKINS-26093 [ JENKINS-26093 ]
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-26619 [ JENKINS-26619 ]
          Jesse Glick made changes -
          Link New: This issue depends on JENKINS-27901 [ JENKINS-27901 ]

          Tom FENNELLY added a comment - - edited

          I hit this issue too. It'll cause a bit of head scratching if you don't have the source at hand to see what's expected.

          Tom FENNELLY added a comment - - edited I hit this issue too. It'll cause a bit of head scratching if you don't have the source at hand to see what's expected.
          Antonio Muñiz made changes -
          Link New: This issue is duplicated by JENKINS-34590 [ JENKINS-34590 ]

          Marcus Philip added a comment -

          I had this too. Pretty confusing. It's pretty bad that the code generator generates invalid code. Can you at least do something if you can't solve the core issue?

          Marcus Philip added a comment - I had this too. Pretty confusing. It's pretty bad that the code generator generates invalid code. Can you at least do something if you can't solve the core issue?

            danielbeck Daniel Beck
            nharniman Nigel Harniman
            Votes:
            38 Vote for this issue
            Watchers:
            43 Start watching this issue

              Created:
              Updated:
              Resolved: