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

Add the api method to configure the 'Active Choices Reactive Parameter' 'Use Groovy Sandbox' attribute

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major Major
    • job-dsl-plugin
    • None
    • Jenkine Version: 2.440.1
      Job DSLVersion: 1.87

      Currently whenever the Job is configured with  'Active Choices Reactive Parameter' the default is 'Use Groovy Sandbox' is unselected, which is essential for the active choice proper functionality.

       

      Example job:

       

      pipelineJob('DynamicChoiceJob-DSL') {
        description('Test Job used for temporarily testing any pipeline run using the replay functionality')
        logRotator {
          numToKeep(120)
          daysToKeep(60)
        }
        parameters {
          booleanParam {
            name('RUN_TESTS')
            description('Run tests')
            defaultValue(true)
          }
          activeChoiceReactiveParam('TEST_TYPES') {
            description('Dynamic Test types based on the Run tests param')
            choiceType('CHECKBOX')
            referencedParameter('RUN_TESTS')
            groovyScript {
              
                script("""\
                if(RUN_TESTS) {
                  return ['default', 'code_coverage', 'newman']
                } else {
                  return []
                }
              """.stripIndent())
              
              
            }
          }
        }
      } 

       

      The result job is configured with the 'Use Groovy Sandbox' is unselected, which whenever the RUN_TESTS is selected/unselected nothing happens while when  'Use Groovy Sandbox' is manually selected in Job config. the functionality started to work as expected. (screen shots)

       

       

      Feature:

      Add the sandbox api method to the script and fallbackScript

      e.g.

      groovyScript {
        script { 
         script(String) 
         sandbox(Boolean) 
        }
        
        fallbackScript {
          script(String)
          sandbox(Boolean)
        }
      } 

       

          [JENKINS-72885] Add the api method to configure the 'Active Choices Reactive Parameter' 'Use Groovy Sandbox' attribute

          Martin added a comment - - edited

          Hi harvynbb 

          I have the same issue, for now my solution was to use "activeChoice" for Groovy Sandbox, with this it works:

           

          activeChoice {
          name(String value)
          description(String value)
          randomName(String value)
          script {
          // Use a Groovy script to define the parameter.
          groovyScript {
          script {
          script(String value)
          // If checked, run this Groovy script in a sandbox with limited abilities.
          sandbox(boolean value)
          // Additional classpath entries accessible from the script.
          classpath {}
          oldScript(String value)
          }
          fallbackScript {
          script(String value)
          // If checked, run this Groovy script in a sandbox with limited abilities.
          sandbox(boolean value)
          // Additional classpath entries accessible from the script.
          classpath {}
          oldScript(String value)
          }
          }
          scriptlerScript {}
          }
          choiceType(String value)
          filterable(Boolean value)
          filterLength(Integer value)
          }

           

          Martin added a comment - - edited Hi harvynbb   I have the same issue, for now my solution was to use "activeChoice" for Groovy Sandbox, with this it works:   activeChoice { name( String value) description( String value) randomName( String value) script { // Use a Groovy script to define the parameter. groovyScript { script { script( String value) // If checked, run this Groovy script in a sandbox with limited abilities. sandbox( boolean value) // Additional classpath entries accessible from the script. classpath {} oldScript( String value) } fallbackScript { script( String value) // If checked, run this Groovy script in a sandbox with limited abilities. sandbox( boolean value) // Additional classpath entries accessible from the script. classpath {} oldScript( String value) } } scriptlerScript {} } choiceType( String value) filterable( Boolean value) filterLength( Integer value) }  

            jamietanna Jamie Tanna
            harvynbb Harvy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: