Save values in parameterized build - jenkins

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.

Related

Is it possible for Pipeline job parameters to change dynamically?

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.

Need to select multiple values as default dynamically in jenkins

In a prameter need to select multiple values as default dynamically in jenkins. Because need to run a scheduler on which multiple values should be selected as default. Any suggestion please.
You can use Extended Choice Parameter Plugin to select multiple valued for a variable.
After installing the plugin, in your project configuration page select This Project is Parameterized option and then from the drop-down choose Extended Choice Parameter.
Then add a name for your parameter and choose the parameter type as Multi Select. Then under Choose Source for Value section choose from where you want to take the vales for your parameter and save your job. In the following image I am providing the value in the job itself. You can choose alternate methods.
Now when you build your project you can select multiple values.
you can try to use source for default value
I would suggest Active Choices instead, using for example a simple checkbox configuration

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

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

How to store last value of parameter in parameterized job as a default value for next build in Jenkins?

I have been using Jenkins for a few weeks and I have one small problem. I can't find any plugin or solution for storing the last value of a parameter in a parametrized job as a default value for the next build.
For example:
My parameter takes build version (1.0.0.01) in the first build. In the next build it will be changed to 1.0.0.02, but I want to have a 1.0.0.01 in the default value field as a hint.
Does anybody have a solution or advice?
The Persistent Parameter Plugin is exactly what you are looking for!
You just need to download it from the official Jenkins repository and install it, no need for any additional setup.
Then on your job, you just need to add a "Persistent Parameter" in order to have default values used and saved between builds.
You can add a System groovy build step to your job (or maybe a post build Groovy step) using the Jenkins API to directly modify the project setting the default parameter value.
Here is some code that may be useful to get you started:
import hudson.model.*
paramsDef = build.getParent().getProperty(ParametersDefinitionProperty.class)
if (paramsDef) {
paramsDef.parameterDefinitions.each{ param ->
if (param.name == 'FOO') {
println("Changing parameter ${param.name} default value was '${param.defaultValue}' to '${param.defaultValue} BAR'")
param.defaultValue = "${param.defaultValue} BAR"
}
}
}
Have a look at the class ParameterDefinition in the Jenkins model.
You probably need to modify the default param value based on the current build executing. Some code to get that would look like this:
def thisBuildParamValue = build.buildVariableResolver.resolve('FOO')
The Extended Choice Parameter plugin provides this capability by using default parameter values from a properties file. A default parameter can be selected from a specified property key and this key can be programmatically modified in your current build. I would then use a groovy script in the current build to set the value of the default property key for the next build.
As an example you would have an Extended Choice Parameter whose default value is defined by a properties file version.properties with keys as follows:
versions=1.0.0.02, 1.0.0.01, 1.0.0.00
default.version=1.0.0.02
The parameter definition would include:
Property File=version.properties
Property Key=versions
Default Property File=version.properties
Default Property Key=default.versions
The GUI for your parameter in the next build would show a selection list with 1.0.0.02 selected by default. This feature is also very useful for pipeline builds where you would want the parameters of a downstream build stage to be set by an earlier build.
The only drawback to this approach might be that the parameter UI will be a drop-down selection. You may opt to have a single value in the versions property key so not to confuse your users.
Similar to thiagolr's answer, but for those of you using pipelines! It appears the persistent-parameter-plugin doesn't work for those using pipeline 2.0. But there is a patched version at https://github.com/ashu16815/persistent-parameter-plugin which seems to work for me.
Clone it locally:
git clone https://github.com/ashu16815/persistent-parameter-plugin.git
Build it:
mvn clean install
Install it in Jenkins:
1) Navigate to Jenkins > Manage Jenkins > Manage Plugins
2) Click Advanced tab
3) Scroll down to Upload Plugin
4) Click Choose file and select the persistent-parameter.hpi in the target directory of the maven build above
Now it should persist.

Resources