Disabling/enabling parameters basing on value from the other parameter

13,646 views
Skip to first unread message

Wojciech Korzenny

unread,
Feb 11, 2015, 2:53:38 AM2/11/15
to jenkins...@googlegroups.com
Hi.

I'm trying to configure job in Jenkins with some list of parameters.
I'd like have some PARAMETER_X which turns to read-only (or disappeared at all) when PARAMETER_Y (simple choice parameter or choice parameter supplied by Scriptler) has value XYZ, otherwise PARAMETER_X is read-write (string/choice parameter).

Is it possible?

W.

Maciej Jaros

unread,
Feb 11, 2015, 3:06:52 AM2/11/15
to jenkins...@googlegroups.com
I don't think there is a plugin for that but you could implement that with a user-side script.

Here is something you might want to start with:
https://github.com/Eccenux/jenkins-scripts

Specifically this is a script used for grouping (hiding a group of parameters based on a checkbox state):
https://github.com/Eccenux/jenkins-scripts/blob/master/theme/nux-js/parameter-grouping.js

Regards,
Nux.

Wojciech Korzenny

unread,
Feb 11, 2015, 6:25:26 AM2/11/15
to jenkins...@googlegroups.com, mac...@mol.com.pl
Hi Maciek,

Thanks for the answer. It looks really promising.
But I have some problems with applying this feature.

I installed plugin Simple Theme Plugin successfully.
I downloaded entire content from github and what should I do now to see "Group Start" parameter type on list during job Configuration?

Thanks in advance.
W.

Maciej Jaros

unread,
Feb 11, 2015, 6:38:54 AM2/11/15
to Wojciech Korzenny, jenkins...@googlegroups.com
W dniu 2015-02-11 o 12:25, Wojciech Korzenny pisze:
Hi Maciek,

Thanks for the answer. It looks really promising.
But I have some problems with applying this feature.

I installed plugin Simple Theme Plugin successfully.
I downloaded entire content from github and what should I do now to see "Group Start" parameter type on list during job Configuration?

That script doesn't define new parameter types. It uses existing ones with special values which - I admit - is a bit hackish ;-). You can find instructions for defining groups in the readme:
https://github.com/Eccenux/jenkins-scripts/#grouping-parameters

There is also a request to make it a standard Jenkins feature with a new "group" definition (instead of a hacky version I use):
https://issues.jenkins-ci.org/browse/JENKINS-19002

Regards,
Nux.

Wojciech Korzenny

unread,
Feb 11, 2015, 7:13:24 AM2/11/15
to jenkins...@googlegroups.com, wkor...@gmail.com, mac...@mol.com.pl
This is how I understood it on the very beginning but when I named my choice parameter "group-start" and followed desription, the result was like in attachment (Build.png, configuration in configure.png). It just looks like standard choice parameter without your functionality.

I think the problem is just with applying this script to jenkins. Where is the place I should put it in order to make it executed while I use choice parameter with name "group-start"? Is there any specific directory in jenkins configuration for such purposes? Or I should point it somewhere from jenkins webconsole like in "Manage jenkins"?
Sorry if my questions are infantile but I'm not familiar with such hacking jenkins :)

W.
Build.png
configure.png

Wojciech Korzenny

unread,
Feb 11, 2015, 11:29:30 AM2/11/15
to jenkins...@googlegroups.com, wkor...@gmail.com, mac...@mol.com.pl
I have specified URL of a theme Js to point at theme.js file.
During logging I see info about username what is brought with theme.js as well

I've tried to create very simple job using group-start feature (collapsed option, other as well) - config.xml in attachment.
It doesn't work as expected.

Is there anything what I'm missing?

W.


I'm attaching config.xml file related with jenkins job where I want to use
config.xml

Maciej Jaros

unread,
Feb 12, 2015, 4:44:21 AM2/12/15
to Wojciech Korzenny, jenkins...@googlegroups.com
Hi.

I added example grouping `config.xml` that has some more explanations
inside:
https://github.com/Eccenux/jenkins-scripts/blob/master/example-grouping/config.xml

Also added screenshots in the Readme:
https://github.com/Eccenux/jenkins-scripts/

Regards,
Nux.

Ioannis Moutsatsos

unread,
Feb 12, 2015, 9:33:21 PM2/12/15
to jenkins...@googlegroups.com
W,
I have been able to generate the required behavior using the 'uno-choice' plugin

Please, download this plugin from the BioUno Developers forum, since we have not yet released it to Jenkins

You can get the latest version in this thread:

The uno-choice plugin provide a new parameter type that can be refreshed when other UI parameters change. In addition, the parameter can be rendered as any well formed HTML using the Dynamic Reference Parameter type.

To recreate the behavior that you want, you'll need two parameters. Lets say PARAM_A (provides the value for the conditional logic) and PARAM_B (conditionally hidden)

PARAM_B will be an uno-choice dynamic reference parameter and it will reference PARAM_A

All you need is to write a groovy script, that returns well formatted HTML to render PARAM_B when PARAM_A takes different values.

Personally, when I want to hide something I simply return a horizontal line HTML element . To return a visible value dynRefParam your groovy script should return something like:

return "<input name=\"value\" value=\"${dynRefParam}\" class=\"setting-input\" type=\"text\">"

Hope this helps you.
Best regards
Ioannis

Rohit Rajpoot

unread,
Jul 27, 2018, 7:31:06 AM7/27/18
to Jenkins Users
Please find below my findings with solution [without using Mask Passwords plugin]:

**Brief Description about my jenkins job:**
I wrote a job which downloads the artifacts from Nexus based on the parameters given at run-time and then makes a Database SQL connection and deploy the SQL scripts using maven flyway plugin. My job takes - Environment, Database Schema, Artifact version number, Flyway command, Database User and it's password as input parameters.

**Brief Background about problem:**
While passing the PASSWORD as MAVEN GOAL (Parameter), it was coming in Jenkins Console as a plain text.
Although I was using "Password Parameter" to pass the password at run-time but then also it was coming as plain text in console.

I tried to use the "secret text" to encrypt the password but then my job started failing because the encrypted password was getting passed to Maven Goals, which was not able to connect to DB.

**Solution:**

I used ***"Inject passwords to the build as environment variables"*** from Build Environment and defined its value as my "password parameter" (my password parameter name was db_password) which I am passing as parameter at run-time (eg.: I defined my inject password value as : ${db_password}  ).

And this is working as expected. The password which I am passing while running my job is coming as [*******]

> [console log:
Executing Maven:  -B -f /work/jenkins_data/workspace/S2/database-deployment-via-flyway-EDOS/pom.xml clean compile -Ddb=UAT_cms_core -DdatabaseSchema=cms-core -Dmode=info -DdeploymentVersion=1.2.9 -Ddb_user=DB_USER -Ddb_password=[*******]
]

Regards, 
Rohit Rajpoot
Reply all
Reply to author
Forward
0 new messages