Jenkins - Active Choice Reactive Reference - jenkins

I am using Active Choices Plugin to dinamically load parameters. I want to read last line of a $workspace file as a parameter.
In this example, when selecting "pedro" username it should display linea 1" because is the last line of the document that is in "/var/lib/jenkins/workspace/Aa.test1.txt"
This is how the job is configured:
And this is when trying to build the job with parameters:
If I execute it in Jenkins Script console it displays the output correctly...
Thank you.

Instead of "choice parameter" you should use "Active choice parameter" and use the name as a referenced parameter in "Active choice Reactive parameter" and finally you can use the name given for "Active choice reactive parameter" as a referenced parameter in "Active choice Reactive Reference parameter".

I think you got the idea wrong. You're using Reactive parameter for "username" but forgetting to specify which parameter to react to. See empty "Referenced parameters" text field in "username" parameter definition.
The logic is pretty simple. When your "referenced parameter" has changed it makes Reactive choice to rebuild dependent parameter (username) and show the value according to the logic implemented as Groovy script.

Related

How can we give option to enter a text input in Active Choice Reactive Reference Parameter and to be able to read a file param in its groovy script?

I am trying to use active choice reactive reactive reference parameters in Jenkins Freestyle Job where I want to read a file and show some of its content as value of this reactive reference parameter, and also to be able to edit the input.
Can this be achieved?
The configuration looks like this as of now :
The output I am expecting is something like this:
This is the input textbox where "ABS= DEF= " is output from fileconfig param, and also this input is not hidden and can be edited if need be, and then should be passed to Jenkins build as parameter.
Note: I used : return "<input name="value" type="text">" in groovy script which is also not working for me.

Parameterized Jenkins job with dependent parameter

I am trying to create a Jenkins job that has dependent parameters.
Firstly I want to be able to choose a main parameter:
And then secondly to be able to choose from a set of options that are dependent parameters of the main parameter.
If I select a different main parameter:
I then want to have a different set of options as the dependencies to the second main parameter.
Please, can you help me with how I can achieve this?
I would suggest the Active Choices plugin (also known as "uno-choice"). (This question has references to both, though they're not the accepted answer.)
For your specific use case, you'll want to add two parameters to your job:
Active Choices Parameter
Name: MainOption
Script: Groovy Script
return ['A','B']
Active Choices Reactive Parameter
Name: DependentOption
Script: Groovy Script
def choices
switch(MainOption){
case 'A':
choices = ['Blue','Green','Yellow']
break
case 'B':
choices = ['Black','White','Grey']
break
default:
choices = ['N/A']
break
}
return choices
Fallback Script: Groovy Script
return ['Option error']
Referenced parameters:
MainOption
The "Referenced parameters" setting is the key - when that value is changed, the plugin will re-evaluate the Groovy script, giving you the dependent parameter effect.
For all of you who stumble upon the same kind of problem (like I did). There is a fairly new Jenkins plugin available that does exactly what is desired here: display a dependent set of drop-downs, updating dependent boxes when a main box changes selection.
For your job you just need to follow the following steps:
Install "Multiselect Parameter Plugin"
The "multiselect parameter plugin" can be installed from Jenkins plugin management, the documentation is available on its Jenkins Plugin page.
Add new parameter
Use "Multiselect Parameter" type
Set name to a sensible value
give a short description
configure like shown below:
H,Main option,Dependent option
V,SELECTED_MAIN,SELECTED_DEPENDENT
C,A,Blue
C,A,Green
C,A,Yellow
C,B,Black
C,B,White
C,B,Grey
Use selected values
When you run "build with parameters" in your job, the following boxes are displayed for selection:
In your build script you can simply use the configured environment variables SELECTED_MAIN and SELECTED_DEPENDENT, which contain the selected values from both select boxes.

Jenkins control on multiple choice parameter to list the apps

I have a requirement in Jenkins as below.
1) Select environment in choice parameter i.e. prod/staging/sit
2) Based on the above environment value, I need to run execute .SH file to fetch the list of deployed applications from my runtime.
3) Populate the retrieved data again in to a choice parameter and allow user to submit for any start/stop action.
Is it possible in Jenkins to trigger an action based on user selected value in choice parameter? something like AJAX....
it is possible in Jenkins to do a choice active based choices.
you need to add a parameter named "Active Choices Reactive Parameter"
in this parameter there is a field named "Referenced Parameter",
whenever this value is changed the Parameter get's reevaluated based on the changed value

Jenkins - Textarea parameter plugin set default value from property file?

I'm trying to find jenkins parameter plugins to do;
Editible textbox (multiline)
Set default text from property file (something like groovy script)
Can you please suggest any plugins?
I tried Active chioce parameter plugin, Extended choice parameter plugin. But those are only provide choice option not textarea.
And Dynamic parameter plugin also seems not support multi-line.
Exists a way in jenkis jobs configuration to pass text parameter to execute a job. Adding Text Parameter, you can define a simple text multiline parameter, where users can enter a text value, which you can use during a build, either as an environment variable, or through variable substitution in some other parts of the configuration.
To define parameters for your job select "This build is parameterized", then using the drop-down button to add as many text parameters or other type as you need.
more info look at
Parameterized Build

Jenkins Active Choices Plug-in with alias names

I'm using jenkins to build an ant project.
The target names in the build.xml are too verbose.
How can I give the target a more user-friendly name?
For example:
I want to change server_remote_stop to "Stop Server", and server_remote_start to "Start Server" without modifying the target names in build.xml (because this build.xml is used by other programs).
Is this possible?
Yes, it is possible, but you will need to use a different Active Choices parameter type: Reactive Reference Parameter.
Here are the settings that I used:
One active choices parameter named PARAMETER1 with some random server names (AAA, BBB)
One active choices reactive reference parameter, that is watching PARAMETER1, has Choice type as "Formatted HTML", has the Advanced option "Omit value" checked, and the following script:
html ="""
Start Server $PARAMETER1
Stop Server $PARAMETER1
"""
This kind of Formatted HTML is rendered in the UI as HTML, and you can mimic HTML components used in Jenkins, like a select box (you can use a radio, checkbox, etc). What is important is that you return some element whose name is "value" and omit the value field that is automatically created by the plugin (thus the advanced option Omit Value).
Since it is a reactive parameter, you can reference other parameters in your Groovy script as well :-)
Hope that helps,
Bruno

Resources