Is it possible for Pipeline job parameters to change dynamically? - jenkins

Is it possible to add or remove parameters for a job based on the value of other parameters?
For example, if there were a DEPLOY boolean parameter, could there then be a DEPLOY_LOCATION which is only visible if and when DEPLOY is set to TRUE?

AFAIK this is not possible. You can only use an input step.

Related

How can I override a jenkinsfile's default parameters?

Sometimes, we want to create multiple jobs that use the same Jenkinsfile instead of a single one. This could happen for example because we want to maintain logs divided based on parameters, instead of having a single job on which look for the right log.
However, in this case, we can't use the parameter definition in the Jenkinsfile, because whatever default value we would define on the job instance would be overwritten by the following execution with whatever is defined in the Jenkinsfile (and this is also happening if we don't define a default value).
So, in this situation, the only way we figure out is to remove the parameter definition in the Jenkinsfile and define the parameters directly on the jobs, which is kind of not optimal.
I mean, I agree that this is the right behavior in most of the cases, as you don't want your parameter to be out of synch and not versioned, but is there a way to specify to Jenkins to skip the parameter reconfiguration or to override the default parameter written in the Jenkinsfile? Something that can be activated/deactivated job by job.
Had this problem myself, we solved it like this:
string(name: 'parameterName', defaultValue: params.parameterName ?:'your default value')
Now the default values defined through Jenkins job configuration will not be overridden.

Parameterized job always run with default parameter

I am having troubles to force Jenkins job to always run with default parameter. Does anyone know the possible plugin to help with that case? Right now I am using extended parameter choice, but still there is no option to just run the job with default value without asking user for parameter.
Solution 1
Currently there is not a straight forward solution to run a parameterized job with default parameter using a plugin. However there is a workaround to accomplish that using the EnvInject Plugin.
As #General_Code noted:
Just add the build step, set the variable like: var1=value and then
use it using ${var1}
Solution 2
As #RejeeshChandran noted:
a more robust solution is the Parameterized Build Plugin which provides the functionality of defaults values for the parameters.
Note
Note that Parameter Defaults Options is a plugin under development which will solve exactly this request. When it is released, you will be able to set it up so your parameter will get a default value when you run it manually.
you can use this plugin Parameterized Scheduler
allow you to write a cron expression with the parameters inside like this
H(0-29)/10 * * * * % name=value; othername=othervalue
Documentations
Use This build is parameterized option in Jenkins configuration. Here you can add default values to the parameters. It will run with default value if the user doesn't change it. It is good to have configurable parameter before running the job.
For configuration details see https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build. You can have multiple parameters.
Go to your jenkins job -> Configure -> General Tab
Add all options in "Description" but the default option in "Default Value"
enter image description here

Generating a dynamic parameter in Jenkins based off a parameter from the same job

I've got a Jenkins build with a choice box for build prefixes by release. It helps trigger a job based off the value of whatever specific build the person wanted.
I wanted to take the value of that choice box and transform the variable into the correct prefix based off the naming conventions typically used on this server for triggering the job based off its name.
So let's say I've got build prefix choices specifically for,
ReleaseOne
ReleaseTwo
none
For none, meaning the parameters used won't try to access or set any specific release-based info by triggering the non-release-specified build.
I wanted to take the value of Release_Prefix and transform it, if needed, for the job that I trigger later. I was hoping to accomplish this with a dynamic parameter or similar mechanism. I'm not sure if my script is bugged, or something fundamental is not working to my intent. This might be the case, based off some alluded feedback from a similar question.
Can I do something like this snippet below? If not with Dynamic Parameter plugin + GroovyScript, what would you suggest? This currently seems to return nothing, regardless of my choice.
Formatted_Prefix parameter, Dynamic Parameter
switch(binding.getVariables().get("Release_Prefix"))
{
case "none":
return "";
case "ReleaseOne":
return "ReleaseOne_";
case "ReleaseTwo":
return "ReleaseTwo_";
default:
def prefix = binding.getVariables().get("Release_Prefix")
return "$prefix_";
}
There's multiple ways I can overcome this, but if I can do it at the initial parameter stage, that would be best for me.
You can use EnvInject Plugin for this.
check the checkbox Prepare an environment for the run and
write your script inside Evaluated Groovy script text box
def prefix1 = Release_Prefix + "mydata"
return[prefix:prefix1]

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

Save values in parameterized build

I am using parameterized build in Jenkins? Is there a way when changing the values of parameters (String parameters for example) to save them for next build instead of using the default?
You can use Extended choise parameter plugin and set default value source to file as described in another question.

Resources