Reputation: 123
I want achieve Picture 3. If no need update, give default value. If need update, then give user input area.
I'd like use active reactive Reference in Jenkins pipeline code, not the jenkins GUI. Checked the example, but user cannot input the value by them self, only provide choices. As we can see the Jenkins GUI picture 1 and 2 can use "Formatted HTML" do this, but how can we use it in pipeline or convert it to pipeline?
Upvotes: 3
Views: 15654
Reputation: 41
Thanks Markzhu;
I ran into the same problem and this solution really helped!
You really don't need to use a Jenkinsfile though. You can just add the code to the reactive parameter like this.
if(NeedUpgradePC.equals('yes')) {
inputBox="<input name='value' type='text' value='Intel Core i5'>"
} else {
inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
}
But the better option is to stop using text and use a checkbox instead. Here is how you check the value of a checkbox.
if (NeedUpgradePC.equals('on')){
inputBox="<input name='value' type='text' value='Intel Core i5'>"
} else {
inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
}
Upvotes: 3
Reputation: 123
========I made it====== here is the code.
parameters([
choice(name:"NeedUpgradePC",choices:['yes','no'],description: "Do you need upgrade your PC"),
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: 'Please provide a Elastic alias label',
name: 'PC_RAM',
randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'NeedUpgradePC',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script:
'return[\'nothing.....\']'
],
script: [
classpath: [],
sandbox: true,
script:
"""
if(NeedUpgradePC.equals('yes')) {
inputBox="<input name='value' type='text' value='Kingston 8GB'>"
} else {
inputBox="<input name='value' type='text' value='Kingston 8GB' disabled>"
}
"""
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: 'Please provide a Elastic alias label',
name: 'PC_CPU',
randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'NeedUpgradePC',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script:
'return[\'nothing.....\']'
],
script: [
classpath: [],
sandbox: true,
script:
"""
if(NeedUpgradePC.equals('yes')) {
inputBox="<input name='value' type='text' value='Intel Core i5'>"
} else {
inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
}
"""
]
]
]
])
Upvotes: 6