Home > Software design >  How to add radio buttons in Jenkins using groovy when building a job using "Build with paramete
How to add radio buttons in Jenkins using groovy when building a job using "Build with paramete

Time:05-11

I am trying to add radio buttons in Jenkins instead of checkboxes when running Build with Parameters. In my existing code, I am getting checkboxes. What changes should I make in my existing code to get the radio buttons. Below is my groovy code:

def call(Map config = [:]) {

    paramsList = []

    paramsList << booleanParam(name: 'deployToDev', defaultValue: false, description: 'Set to true to deploy to Dev K8s Environment')
    paramsList << booleanParam(name: 'deployToTest', defaultValue: false, description: 'Set to true to deploy to Test K8s Environment')
    paramsList << booleanParam(name: 'deployToStage', defaultValue: false, description: 'Set to true to deploy to Stage K8s Environment')
    properties([parameters(paramsList)])
}

Please find the below screenshot: enter image description here

CodePudding user response:

You can achieve that easily using the enter image description here

You can also use the Active Choices plugin, which is a bit more complicated but has more configuration options, it will also allow you to generate the values from a groovy script.
For example:

properties([parameters(
   [[$class: 'ChoiceParameter', name: 'DeployTo', choiceType: 'PT_RADIO', description: 'Select the environment to deploy to', script: [$class: 'GroovyScript', script: [classpath: [], sandbox: false, script: "return ['Dev','Test','Stage']"]]]]
)])
  • Related