Jenkinsfile中Active Choice Reactive Reference Parameter使用报错求助
Fixing Active Choice Reactive Parameters in Jenkinsfile
Let's work through your issue step by step. The error The properties section has been renamed as of version 0.8. Use options stems from two main problems: outdated parameter class names from the Active Choice plugin, and a minor syntax adjustment for modern Jenkins Pipeline versions.
Key Issues in Your Original Code
- Deprecated Parameter Classes:
ChoiceParameterandCascadeChoiceParameterare no longer the correct classes for Active Choice parameters in newer plugin versions. You need to useActiveChoiceParameter(for static dropdowns) andActiveChoiceReactiveParameter(for cascading/reactive options) instead. - Pipeline Syntax Misalignment: If you're using a Declarative Pipeline, the
propertiesblock needs to be wrapped inside theoptionsblock (as the error hints). For Scripted Pipeline,propertiesworks directly, but we'll update it to align with current best practices. - Groovy Script Tweaks: Your reactive script had an unclosed string literal and could be made more robust to handle edge cases.
Corrected Jenkinsfile Code
For Declarative Pipeline
pipeline { agent any options { properties([ parameters([ // Static Active Choice Parameter for Environment [$class: 'ActiveChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: 'Select the Env Name from the Dropdown List', filterLength: 1, filterable: true, name: 'Env', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: 'return ["Could not get Env"]' ], script: [ classpath: [], sandbox: false, script: 'return ["Dev","QA","Stage","Prod"]' ] ] ], // Reactive Active Choice Parameter for Servers [$class: 'ActiveChoiceReactiveParameter', choiceType: 'PT_CHECKBOX', description: 'Select Servers', filterLength: 1, filterable: true, name: 'Server', referencedParameters: 'Env', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: 'return ["Could not get Environment from Env Param"]' ], script: [ classpath: [], sandbox: false, script: ''' def envName = binding.get('Env') ?: '' switch(envName) { case "Dev": return ["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"] case "QA": return ["qaaaa001","qabbb002","qaccc003"] case "Stage": return ["staaa001","stbbb002","stccc003"] case "Prod": return ["praaa001","prbbb002","prccc003"] default: return ["No servers found for selected environment"] } ''' ] ] ] ]) ]) } stages { stage('Verify Parameters') { steps { echo "Selected Environment: ${params.Env}" echo "Selected Servers: ${params.Server}" } } } }
For Scripted Pipeline
properties([ parameters([ [$class: 'ActiveChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: 'Select the Env Name from the Dropdown List', filterLength: 1, filterable: true, name: 'Env', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: 'return ["Could not get Env"]' ], script: [ classpath: [], sandbox: false, script: 'return ["Dev","QA","Stage","Prod"]' ] ] ], [$class: 'ActiveChoiceReactiveParameter', choiceType: 'PT_CHECKBOX', description: 'Select Servers', filterLength: 1, filterable: true, name: 'Server', referencedParameters: 'Env', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: 'return ["Could not get Environment from Env Param"]' ], script: [ classpath: [], sandbox: false, script: ''' def envName = binding.get('Env') ?: '' switch(envName) { case "Dev": return ["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"] case "QA": return ["qaaaa001","qabbb002","qaccc003"] case "Stage": return ["staaa001","stbbb002","stccc003"] case "Prod": return ["praaa001","prbbb002","prccc003"] default: return ["No servers found for selected environment"] } ''' ] ] ] ]) ]) node { stage('Verify Parameters') { echo "Selected Environment: ${params.Env}" echo "Selected Servers: ${params.Server}" } }
What Changed?
- Updated Parameter Classes: Switched to the official, supported classes
ActiveChoiceParameterandActiveChoiceReactiveParameterto resolve plugin compatibility issues. - Fixed Pipeline Syntax: For Declarative Pipeline, wrapped
propertiesinsideoptionsto eliminate the version warning. For Scripted Pipeline, keptpropertiesat the top but updated parameter classes. - Robust Groovy Script:
- Used
binding.get('Env')to safely retrieve the parameter value (avoids scope-related errors) - Added a
defaultcase to handle unexpected environment selections - Fixed string formatting and closed all literals properly
- Used
- Removed Unnecessary Field: The auto-generated
randomNamefield is not required in Pipeline definitions—Jenkins handles this automatically.
Additional Tips
- Ensure the Active Choices Plug-in and its dependency Active Choices Reactive Reference Parameter are installed and updated to the latest compatible version in your Jenkins instance.
- If sandbox-related errors occur, you can either:
- Enable sandbox mode and approve required Groovy methods in Manage Jenkins > In-process Script Approval
- Keep sandbox mode disabled (as you did) but ensure only trusted users can modify your pipelines.
内容的提问来源于stack exchange,提问作者naresh mahato
相关产品推荐
相关产品推荐

