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

          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: