Jenkins中基于build_type选择的条件参数实现插件咨询
Dynamic Parameter Visibility in Jenkins Based on Selection
Absolutely! You can totally pull off this dynamic parameter behavior in Jenkins with a couple of solid plugins. Here are the most reliable and widely-used options to make your build_type selection control the visibility of the snapshot name input:
1. Active Choices Plugin (Recommended)
This plugin is the go-to for dynamic, reactive parameters in Jenkins. Here's how to set it up:
- First, install the Active Choices Plugin and its companion Active Choices Reactive Reference Parameter Plugin from Jenkins' plugin manager.
- Create your initial
build_typeparameter as a Choice Parameter, with optionsDaily,Release, andSnapshot. - Add a new parameter of type Active Choices Reactive Reference Parameter:
- Under "Referenced parameters", enter
build_type(this links it to your selection). - Choose "Groovy Script" as the script type, then add this logic:
if (build_type == 'Snapshot') { return ['Snapshot Name:'] } else { return [] } - Set the "Parameter Type" to Textbox — this will create an input field only when
Snapshotis selected (since the script returns a label in that case, and nothing otherwise).
- Under "Referenced parameters", enter
2. Extended Choice Parameter Plugin
Another great option that's straightforward for conditional visibility:
- Install the Extended Choice Parameter Plugin from the plugin manager.
- Create your
build_typeChoice Parameter as before. - Add a new Extended Choice Parameter:
- Set the "Parameter Type" to Text Input (this will be your snapshot name field).
- Scroll to the "Visible if" section, and enter the expression:
${build_type} == 'Snapshot' - Save your job configuration — now the snapshot name input will only appear when users select
Snapshotfrom thebuild_typedropdown.
Quick Tips
- Make sure you're running the latest versions of these plugins to avoid any compatibility issues.
- Test your configuration by triggering a build and switching between the
build_typeoptions to confirm the snapshot field shows/hides as expected.
内容的提问来源于stack exchange,提问作者Ras
相关产品推荐
相关产品推荐

