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

In active choice parameter with groovy script, groovy sandbox checkbox gets unchecked after a build

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • active-choices-plugin
    • None
    • Jenkins 2.235.5
      Active Choices Plug-in 2.5.1

      I configured a job using Active Choice Parameter with Groovy Script. I did check "Use Groovy Sandbox" below the script and save.

      I was able to run a build after the initial configuration.

      But after that build, the "Use Groovy Sandbox" checkbox got wipe out and the parameter doesn't display correctly. I had to reconfigure and check that box but I am not able to run it once because it will get wiped out again.

          [JENKINS-64513] In active choice parameter with groovy script, groovy sandbox checkbox gets unchecked after a build

          I was not able to reproduce it. I created a job with a single parameter and with a Groovy script with that checkbox checked.

          Reloaded configuration a couple times, and the checkbox was still checked.

          Executed the job twice, producing two succeeded builds. Checked the checkbox status in-executions, and after both builds were produced. The check box was always selected.

          Same plug-in version, only Jenkins version a bit older 2.204.1. Not sure if the Jenkins version could interfere; or perhaps the Scriptler version?

          If anybody else is able to reproduce in another environment, and if possible to share the config.xml of the job, then I will try it again.

          Thanks

          Bruno

          Bruno P. Kinoshita added a comment - I was not able to reproduce it. I created a job with a single parameter and with a Groovy script with that checkbox checked. Reloaded configuration a couple times, and the checkbox was still checked. Executed the job twice, producing two succeeded builds. Checked the checkbox status in-executions, and after both builds were produced. The check box was always selected. Same plug-in version, only Jenkins version a bit older 2.204.1. Not sure if the Jenkins version could interfere; or perhaps the Scriptler version? If anybody else is able to reproduce in another environment, and if possible to share the config.xml of the job, then I will try it again. Thanks Bruno

          Udayendu added a comment -

          Hi Bruno,

           

          I am using the same setup like Lu and getting the same issue.

          Every time when we are running the build, we are using "Build with Parameters" button and every time its not able to load the required parameters. 

          Then have to click on the Configure and select all the check boxes and save. After that only "Build with Parameters" button is able to load the required parameters.

           

          Thanks,

          Udayendu Kar

          Udayendu added a comment - Hi Bruno,   I am using the same setup like Lu and getting the same issue. Every time when we are running the build, we are using " Build with Parameters " button and every time its not able to load the required parameters.  Then have to click on the Configure and select all the check boxes and save. After that only " Build with Parameters " button is able to load the required parameters.   Thanks, Udayendu Kar

          Thanks Udayendu. I will give it another try, this time with the exact versions, before trying to upgrade Jenkins/libs.

          Bruno P. Kinoshita added a comment - Thanks Udayendu. I will give it another try, this time with the exact versions, before trying to upgrade Jenkins/libs.

          Rock added a comment -

          Hello. I had the same issue and I discovered the cause and solution.
          In my case, I was using the Active Choice Parameter plugin in the Jenkins file, with the following  properties block placed outside the pipeline block:

          properties([
              parameters([
                  [$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT',
                  description: 'Color of the car',
                  name: 'COLOR',
                  script: 
                      [$class: 'GroovyScript',
                      fallbackScript: [classpath: [], sandbox: true, script: 'return ["ERROR"]'],
                      script: [classpath: [], script:  myCustomScript]
                      ]
                  ]
              ])
          ])
          
          pipeline {
              // ...
          }
          

           As can be seen, I included the entry sandbox: true in the key fallbackScript, but not in the one right after it, script. So all I had to do was to set it as:

                      script: [classpath: [], sandbox: true, script:  myCustomScript]
          

          With this set, the "Use Groovy Sandbox" checkbox in the GUI configuration of the pipeline should get checked automatically.
          What was happening to me was that I was checking this checkbox in the GUI configuration for my script, but I was forgetting to explicitly set it in the properties block as well. The properties block was then taking precedence over the GUI configuration of the pipeline and was unchecking that checkbox after each build, i.e. it was overwriting the configuration I was setting in the GUI. In my experience, the latter is always the case. In other words, what we put in a properties block in the Jenkinsfile, overwrites what we set in the GUI configuration of the pipeline for the Active Choice Parameter plugin. And I do like this behavior, as I prefer to have all the settings of my pipelines in Jenkisnfiles (text files) that I can version and easily copy/paste.

          My Jenkins version is 2.414.1 and my Active Choice Parameter plugin version is 2.7.2.

          Hope this help!

          Rock added a comment - Hello. I had the same issue and I discovered the cause and solution. In my case, I was using the Active Choice Parameter plugin in the Jenkins file, with the following  properties block placed outside the pipeline block: properties([ parameters([ [$class: 'ChoiceParameter' , choiceType: 'PT_SINGLE_SELECT' , description: 'Color of the car' , name: 'COLOR' , script: [$class: 'GroovyScript' , fallbackScript: [classpath: [], sandbox: true , script: ' return [ "ERROR" ]' ], script: [classpath: [], script: myCustomScript] ] ] ]) ]) pipeline { // ... }  As can be seen, I included the entry sandbox: true  in the key fallbackScript , but not in the one right after it, script . So all I had to do was to set it as: script: [classpath: [], sandbox: true , script: myCustomScript] With this set, the "Use Groovy Sandbox" checkbox in the GUI configuration of the pipeline should get checked automatically. What was happening to me was that I was checking this checkbox in the GUI configuration for my script, but I was forgetting to explicitly set it in the properties block as well. The properties block was then taking precedence over the GUI configuration of the pipeline and was unchecking that checkbox after each build, i.e. it was overwriting the configuration I was setting in the GUI. In my experience, the latter is always the case. In other words, what we put in a properties block in the Jenkinsfile, overwrites what we set in the GUI configuration of the pipeline for the Active Choice Parameter plugin. And I do like this behavior, as I prefer to have all the settings of my pipelines in Jenkisnfiles (text files) that I can version and easily copy/paste. My Jenkins version is 2.414.1 and my Active Choice Parameter plugin version is 2.7.2. Hope this help!

            rocknnlee Rock
            shen3lu4 Lu Shen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: