How to set Active Choice Parameter's script sandbox via Job DSL

I have a JobDSL script that creates a Jenkins pipeline job with Active Choice parameters provided by Active Choice Parameters plugin. Unfortunately, JobDSL doesn't support parameter that enables running Active Choice Groovy scripts in sandbox (in UI it's available), so I'm trying to enable it via configure block.

Here's my JobDSL script:

pipelineJob("my-pipeline") {
  logRotator(-1, 10)
  parameters {
    activeChoiceParam('Branch') {
      description('Lists branches for integration job')
      filterable()
      choiceType('SINGLE_SELECT')
      groovyScript {
          script("return ['The list of branches']")
          fallbackScript("return ['Unable to list branches']")
      }
    }
    activeChoiceReactiveParam('Build') {
      description('Specifies which build from selected branch will be used for deployment. Only builds that contain Terraform plan are listed.')
      choiceType('SINGLE_SELECT')
      groovyScript {
          script("return ['Selected build']")
          fallbackScript("return ['Unable to list builds']")
      }
      referencedParameter('Branch')
    }
    activeChoiceReactiveReferenceParam('Artifacts') {
      description('Lists artifacts from build specified')
      choiceType('FORMATTED_HTML')
      groovyScript {
          script(scriptGen("return ['Job artifacts']")
          fallbackScript("return ['Unable to list artifacts']")
      }
      referencedParameter('Branch')
      referencedParameter('Build')
    }
  }
  definition {
    cpsScm {
      scm {
        git {
          remote {
            github('mainorg/my-repo', 'https', 'github.com')
            credentials('my-creds')
          }
          branch('*/master')
        }
      }
      scriptPath("ci/Jenkinsfile")
      lightweight(true)
    }
  }
  configure { 
      it / 'properties' / 'hudson.model.ParametersDefinitionPropert' / 'parameterDefinitions' / 'org.biouno.unochoice.ChoiceParameter' / 'script' / 'secureScript' {
        'sandbox'('true')
    }
  }
}

With configure block, I'm trying to override values for <secureFallbackScript> and <secureScript> under<sandbox> node, but it doesn't work. It erases all other nodes. I'm not that good at Groovy, so I would really appreciate any help. What is the correct way to override all <sandbox> nodes values to true? Thanks in advance.

Here's a link to job XML for reference: https://gist.github.com/vzabawski/aae51eddd45a51978224e403cc505b5b


The activeChoiceParam, activeChoiceReactiveParam and activeChoiceReactiveReferenceParam functions are parts of the static API. The Job DSL authors introduced the dynamic API. Whenever the dynamic API could be used to do something, the static API responsible for the same logic is no longer supported.

You should read those pages:

  • Job DSL Dynamic API
  • JENKINS-41308 support Use Groovy Sandbox scripts in activeChoiceParams

An example how to switch from the static API to the dynamic API:

activeChoiceParam('Branch') {
  description('Lists branches for integration job')
  filterable()
  choiceType('SINGLE_SELECT')
  groovyScript {
    script("return ['The list of branches']")
    fallbackScript("return ['Unable to list branches']")
  }
}

choiceParameter {
  name('Branch')
  description('Lists branches for integration job')
  filterable(true)
  choiceType('PT_SINGLE_SELECT')
  script {
    groovyScript {
      script {
        script("return ['The list of branches']")
        sandbox(true)
      }
      fallbackScript {
        script("return ['Unable to list branches']")
        sandbox(true)
      }
    }
  }
  randomName('')
  filterLength(0)
}