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

          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 .

          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.

          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?

          Michael Neale added a comment -

          Just hit this.

          Based on how long this is open - do people not really use the choice input, OR, do people not use the snippet builder?
          (would be interesting to know either way).

          Michael Neale added a comment - Just hit this. Based on how long this is open - do people not really use the choice input, OR, do people not use the snippet builder? (would be interesting to know either way).

          R. Tyler Croy added a comment -

          michaelneale, people really use the Choice parameter, but with things like input and properties they're sufficiently difficult to find that I have had a number of people ask me if "parameterized pipelines" are even possible :'(

          I filed JENKINS-38995 today which is an example of this same issue with properties

          R. Tyler Croy added a comment - michaelneale , people really use the Choice parameter, but with things like input and properties they're sufficiently difficult to find that I have had a number of people ask me if "parameterized pipelines" are even possible :'( I filed JENKINS-38995 today which is an example of this same issue with properties

          Michael Neale added a comment -

          201604291_tyler right, so if they do use it, or want to use it, the problem is that people don't find the snippets, but when they do, they don't work? the fact this doesn't work and few complain implies that few find it (or find it useful).

          Parametrised multibranch pipelines are hidden in a disused basement, with a sign on the door saying "beware of the leopard"

          Michael Neale added a comment - 201604291_tyler right, so if they do use it, or want to use it, the problem is that people don't find the snippets, but when they do, they don't work? the fact this doesn't work and few complain implies that few find it (or find it useful). Parametrised multibranch pipelines are hidden in a disused basement, with a sign on the door saying "beware of the leopard"

          R. Tyler Croy added a comment -

          michaelneale, I don't know how you could consider this so far off the beaten path that it's irrelevant. Two of the duplicates were filed by people who work full time on Jenkins. Anecdotally speaking, I had four people ask me about parameters and multibranch pipelines at this ~100 person Jenkins Days event in Denver just last week.

          The problem is that there's no documentation around them so people aren't figuring out to trigger this issue, but IMHO that doesn't mean the bug isn't worth fixing. FWIW, this ticket is coming up on it's two year birthday. >_<

          R. Tyler Croy added a comment - michaelneale , I don't know how you could consider this so far off the beaten path that it's irrelevant. Two of the duplicates were filed by people who work full time on Jenkins. Anecdotally speaking, I had four people ask me about parameters and multibranch pipelines at this ~100 person Jenkins Days event in Denver just last week. The problem is that there's no documentation around them so people aren't figuring out to trigger this issue, but IMHO that doesn't mean the bug isn't worth fixing. FWIW, this ticket is coming up on it's two year birthday. >_<

          Michael Neale added a comment -

          201604291_tyler I guess the point I was trying to make is that fixing this won't necessarily explain to people that parametrised multibranch jobs are possible and awesome, but totally, worth fixing (its more a meta comment on the utility of the snippetizer).

          Michael Neale added a comment - 201604291_tyler I guess the point I was trying to make is that fixing this won't necessarily explain to people that parametrised multibranch jobs are possible and awesome, but totally, worth fixing (its more a meta comment on the utility of the snippetizer).

          Just hit this as well.

          I used the snippet generator and got really confused by the fact that it generates wrong pipeline code.

          The workaround with using \n as separator works fine though, here is some groovy syntactic sugar to solve it:

          def sendToChoices = ['alice@xy.com', 'bob@xy.com', 'somelist@xy.com'].join('\n')
          def userInput = input(message: 'Deploy this build to production?',
                              ok: 'Yes deploy now!',
                              parameters: [choice(choices: sendToChoices, name: 'SEND_EMAIL_TO')]
                      )
          

           

          Stefan Thurnherr added a comment - Just hit this as well. I used the snippet generator and got really confused by the fact that it generates wrong pipeline code. The workaround with using \n as separator works fine though, here is some groovy syntactic sugar to solve it: def sendToChoices = [ 'alice@xy.com' , 'bob@xy.com' , 'somelist@xy.com' ].join( '\n' ) def userInput = input(message: 'Deploy this build to production?' , ok: 'Yes deploy now!' , parameters: [choice(choices: sendToChoices, name: 'SEND_EMAIL_TO' )] )  

          Code changed in jenkins
          User: Daniel Beck
          Path:
          core/src/main/java/hudson/model/ChoiceParameterDefinition.java
          http://jenkins-ci.org/commit/jenkins/bd7fd304a7bc93b4efc1c8f88887e262aa329b86
          Log:
          JENKINS-26143 Make choice parameter work with choices list in pipeline

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: core/src/main/java/hudson/model/ChoiceParameterDefinition.java http://jenkins-ci.org/commit/jenkins/bd7fd304a7bc93b4efc1c8f88887e262aa329b86 Log: JENKINS-26143 Make choice parameter work with choices list in pipeline

          Code changed in jenkins
          User: Daniel Beck
          Path:
          core/src/main/java/hudson/model/ChoiceParameterDefinition.java
          http://jenkins-ci.org/commit/jenkins/f0e56875d08b436a6c7f8e23afca7e59c55d33fc
          Log:
          JENKINS-26143 Apparently only List is allowed

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: core/src/main/java/hudson/model/ChoiceParameterDefinition.java http://jenkins-ci.org/commit/jenkins/f0e56875d08b436a6c7f8e23afca7e59c55d33fc Log: JENKINS-26143 Apparently only List is allowed

          Code changed in jenkins
          User: Daniel Beck
          Path:
          core/src/main/java/hudson/model/ChoiceParameterDefinition.java
          http://jenkins-ci.org/commit/jenkins/6de571632c3873689981c27902ae8269fdf094eb
          Log:
          Merge pull request #3014 from daniel-beck/JENKINS-26143

          JENKINS-26143 Make choice parameter work with choices list in pipeline

          Compare: https://github.com/jenkinsci/jenkins/compare/bb8913759634...6de571632c38

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: core/src/main/java/hudson/model/ChoiceParameterDefinition.java http://jenkins-ci.org/commit/jenkins/6de571632c3873689981c27902ae8269fdf094eb Log: Merge pull request #3014 from daniel-beck/ JENKINS-26143 JENKINS-26143 Make choice parameter work with choices list in pipeline Compare: https://github.com/jenkinsci/jenkins/compare/bb8913759634...6de571632c38

          Daniel Beck added a comment -

          Merged, I expect this will be in Jenkins 2.112.

          Daniel Beck added a comment - Merged, I expect this will be in Jenkins 2.112.

          Code changed in jenkins
          User: Daniel Beck
          Path:
          content/_data/changelogs/weekly.yml
          http://jenkins-ci.org/commit/jenkins.io/ad2121fb5435ee0aad0f5553f606dc8eba565b93
          Log:
          Note JENKINS-26143 in 2.112 changelog

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: content/_data/changelogs/weekly.yml http://jenkins-ci.org/commit/jenkins.io/ad2121fb5435ee0aad0f5553f606dc8eba565b93 Log: Note JENKINS-26143 in 2.112 changelog

          Code changed in jenkins
          User: Daniel Beck
          Path:
          content/_data/changelogs/weekly.yml
          http://jenkins-ci.org/commit/jenkins.io/df8a94b349fd051657d51f43d2b3d3c43ce1355a
          Log:
          Merge pull request #1455 from daniel-beck/changelog-2.112-JENKINS-26143

          Note JENKINS-26143 in 2.112 changelog

          Compare: https://github.com/jenkins-infra/jenkins.io/compare/5f085d28cebf...df8a94b349fd

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Beck Path: content/_data/changelogs/weekly.yml http://jenkins-ci.org/commit/jenkins.io/df8a94b349fd051657d51f43d2b3d3c43ce1355a Log: Merge pull request #1455 from daniel-beck/changelog-2.112- JENKINS-26143 Note JENKINS-26143 in 2.112 changelog Compare: https://github.com/jenkins-infra/jenkins.io/compare/5f085d28cebf...df8a94b349fd

          yan-hong wang added a comment -

          Hello all,

          Since I upgraded Jenkins from jenkins:2.107.3-alpine to jenkins:2.121.1-alpine.

          And I found the dsl with choices have parse error happen when Jenkins start up.

          -------------------------------------------------------------------

              pipelineJob( "$app" ) {

                  properties {
                      nextBuildNumber( "$num".toInteger() )
                      parameters {
                          parameterDefinitions {
                              choiceParam {
                                  name( "$branchName" )
                                  choices( "$branchChoices" )
                                  description( '' )
                              }
                          }
                      }
                  }

              }

          -------------------------------------------------------------------

          I tried to realize the choices syntax of DSL in http://192.168.99.100:30808/plugin/job-dsl/api-viewer/index.html.

          I found the reference of choices expanded to recursive structure...

          What's going on with this function now?

          Thanks very much.

           

          BR

          Hong

          yan-hong wang added a comment - Hello all, Since I upgraded Jenkins from jenkins:2.107.3-alpine to jenkins:2.121.1-alpine. And I found the dsl with choices have parse error happen when Jenkins start up. -------------------------------------------------------------------     pipelineJob( "$app" ) {         properties {             nextBuildNumber( "$num".toInteger() )             parameters {                 parameterDefinitions {                     choiceParam {                         name( "$branchName" )                         choices ( "$branchChoices" )                         description( '' )                     }                 }             }         }     } ------------------------------------------------------------------- I tried to realize the choices syntax of DSL in http://192.168.99.100:30808/plugin/job-dsl/api-viewer/index.html. I found the reference of choices expanded to recursive structure... What's going on with this function now? Thanks very much.   BR Hong

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

              Created:
              Updated:
              Resolved: