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

Inaccurate generated dsl in api-viewer for extensible-choice-parameter-plugin

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • job-dsl-plugin
    • Jenkins ver. 2.7.4
      extensible-choice-parameter:1.3.2
      job-dsl:1.48

      also tried with:
      extensible-choice-parameter:1.3.3
      job-dsl:1.57

      Love the job-dsl-plugin api viewer i.e. <base url>/jenkins/plugin/job-dsl/api-viewer/index.html

      However when browsing the generated dsl for the extensibleChoiceParameter plugin i.e.:
      #method/hudson.model.ParameterDefinition$$List.extensibleChoiceParameterDefinition

      It reports:
      extensibleChoiceParameterDefinition {
      choiceListProvider {
      textareaChoiceListProvider {
      whenToAdd(String value)

      However having tried this DSL:
      myJob.with{
      parameters{
      extensibleChoiceParameterDefinition {
      name='MY_PARAM_NAME'
      choiceListProvider {
      textareaChoiceListProvider

      { choiceListText(“item1\nitem2”) defaultChoice('Top') addEditedValue(false) whenToAdd('triggered') }

      }
      editable(true)
      description('My param')
      }

      It complains:
      ERROR: (script, line 15) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.whenToAdd() is applicable for argument types: (java.lang.String) values: [triggered]
      Finished: FAILURE

      Looking up the plugin source code it does appear to want an ENUM:
      https://github.com/jenkinsci/extensible-choice-parameter-plugin/blob/a2f0d8b271d2badfc34c98c4b9772a6e36b31784/src/main/java/jp/ikedam/jenkins/plugins/extensible_choice_parameter/AddEditedChoiceListProvider.java

      So the bug is that I think the api-viewer is generating the wrong DSL.

      I would perhaps not have raised this, but I don’t seem to be able to get the generated DSL to work at all. Since the ENUM seems to exist in a class that appears to need to run as System Groovy, I can’t import that class in my Job DSL groovy. E.g.
      def temp = new jp.ikedam.jenkins.plugins.extensible_choice_parameter.GlobalTextareaChoiceListProvider()
      unable to resolve class jp.ikedam.jenkins.plugins.extensible_choice_parameter.GlobalTextareaChoiceListProvider
      unless I run in System Groovy step:
      groovy.lang.GroovyRuntimeException: Could not find matching constructor for: jp.ikedam.jenkins.plugins.extensible_choice_parameter.GlobalTextareaChoiceListProvider()
      (shows class is found)

      So possibly another issue is that dsl for classes that have to run as System Groovy don't work if you need ENUMs.

      So I'm raising this bug primarily because I think the generated DSL is incorrect in some circumstances.

      • But also on the off chance that anyone can shed any light on getting my generated DSL working. Thanks in advance!

          [JENKINS-41270] Inaccurate generated dsl in api-viewer for extensible-choice-parameter-plugin

          Next time, try to use the wiki markup to make your bug report readable.

          The DSL Api Viewer is correct, but the enum values are case sensitive. You need to specify them exactly as they are written in code. Do not use the localized values from the UI.

          This works:

          job('example') {
            parameters {
              extensibleChoiceParameterDefinition { 
                name('FOO')
                choiceListProvider {
                  textareaChoiceListProvider {
                    choiceListText('foo\nbar')
                    defaultChoice('bar')
                    addEditedValue(true)
                    whenToAdd('Triggered')
                  }
                }
                editable(true)
                description('lorem ipsum')
              }
            }
          }
          

          The next release will provide a better error message:
          https://github.com/jenkinsci/job-dsl-plugin/pull/988

          Daniel Spilker added a comment - Next time, try to use the wiki markup to make your bug report readable. The DSL Api Viewer is correct, but the enum values are case sensitive. You need to specify them exactly as they are written in code. Do not use the localized values from the UI. This works: job( 'example' ) { parameters { extensibleChoiceParameterDefinition { name( 'FOO' ) choiceListProvider { textareaChoiceListProvider { choiceListText( 'foo\nbar' ) defaultChoice( 'bar' ) addEditedValue( true ) whenToAdd( 'Triggered' ) } } editable( true ) description( 'lorem ipsum' ) } } } The next release will provide a better error message: https://github.com/jenkinsci/job-dsl-plugin/pull/988

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          docs/Home.md
          job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/structs/DescribableContext.groovy
          job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/structs/DescribableContextSpec.groovy
          http://jenkins-ci.org/commit/job-dsl-plugin/b837bb3e370db03af86e90a12eeb8f6b16bb9028
          Log:
          improved error message for invalid enum values

          [FIXES JENKINS-41270]

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: docs/Home.md job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/structs/DescribableContext.groovy job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/structs/DescribableContextSpec.groovy http://jenkins-ci.org/commit/job-dsl-plugin/b837bb3e370db03af86e90a12eeb8f6b16bb9028 Log: improved error message for invalid enum values [FIXES JENKINS-41270]

          Code changed in jenkins
          User: Daniel Spilker
          Path:
          docs/Home.md
          job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/structs/DescribableContext.groovy
          job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/structs/DescribableContextSpec.groovy
          http://jenkins-ci.org/commit/job-dsl-plugin/877e860ea3d8a455a820d723d4ebd0e6ff331269
          Log:
          Merge pull request #988 from daspilker/JENKINS-41270

          JENKINS-41270 improved error message for invalid enum values

          Compare: https://github.com/jenkinsci/job-dsl-plugin/compare/c12c0c4915b8...877e860ea3d8

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Spilker Path: docs/Home.md job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/structs/DescribableContext.groovy job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/structs/DescribableContextSpec.groovy http://jenkins-ci.org/commit/job-dsl-plugin/877e860ea3d8a455a820d723d4ebd0e6ff331269 Log: Merge pull request #988 from daspilker/ JENKINS-41270 JENKINS-41270 improved error message for invalid enum values Compare: https://github.com/jenkinsci/job-dsl-plugin/compare/c12c0c4915b8...877e860ea3d8

          Thanks so much for your help daspilker that's amazing. Feel pretty stupid, could have sworn I tried 'Triggered' but clearly not! And sorry about the lack of markdown. Thanks again and great to see you improved the error handling. Feel free to close.

          Markos Rendell added a comment - Thanks so much for your help daspilker that's amazing. Feel pretty stupid, could have sworn I tried 'Triggered' but clearly not! And sorry about the lack of markdown. Thanks again and great to see you improved the error handling. Feel free to close.

            daspilker Daniel Spilker
            markosrendell Markos Rendell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: