trigger parameterized build on other projects does not pass parameter - jenkins

In a Jenkins pipeline, parameters defined in upstream job is not being passed to downstream job even "current build parameters" option is selected. When I try to echo the parameter value, it is null.
Example: I have checked "This is a parameterized build". There is a string parameter in upstream job called "version" with the default value as "abc". When I run echo $version on the downstream job, in console output I do not see a value being printed.
Environment info:
Jenkins Version: 2.89.3
O/S: CentOs 7
Jenkins installed plugin info:
Build with Parameters: 1.4
Parameterized Trigger plugin:2.35.2

In the downstream job you need to set a variable to accept the parameter being passed.
Example: If foo parameter was passed from upstream job. The downstream should have a parameter (string or one of your choice) same name as foo and default value as $foo.

Finally I found out that the way this parameter works in jenkins 1.x and 2.x versions is different. In the newer version of jenkins, all the down stream projects must be parameterized with the defined parameter and the empty value. However, in Jenkins 1.x was able to pass the parameter from upstream to downstream without defining the parameter in the upstream project. Using only "Current build parameter" was able to do the work but not anymore. Not sure If I am the only one finding it bizarre.

Related

Get value from parameterized remote trigger plugin

I tried to use parameterized remote trigger plugin to pass value to a remote job following https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/README_JobConfiguration.md guide. In the upstream job I input a=b into the Parameters field, but in the downstream job in a Execute Windows batch command step, when I tried to get the value using echo %a% the output is empty. How can I get the value of a from downstream job?
You need to make parameterized downstream job having a as parameter. I think you missed this point.

Load Jenkins build parameters from SCM

Is it possible to have Jenkins pull a prameterized build from SCM (Git)?
I'm currently using "Pipeline script from SCM" where Jenkins retrieves the pipeline script but not the build parameters e.g. "String Parameter", "Choice Parameter", etc.
Jenkinsfile (Jenkins pipelines) are capable of this.
https://jenkins.io/doc/book/pipeline/syntax/#parameters
Be aware that parameters are post processed. So the 1st build will just be "Build" not "Build with parameters". After the 1st build, it will change.
This can be alleviated by using default values and always referencing the params using the full params.PARAM_NAME syntax. Don't just reference it as PARAM_NAME as this will cause Jenkins to search for env.PARAM_NAME by default.
Yes, you can retrieve parameters from a Parametrized Build in a Pipeline script from SCM Jenkins job.
To access them in the Jenkins file, use env.[PARAMETER_NAME].
For example:
echo 'Param value: ' + env.SOME_PARAMETER

Pipeline - Parameterised Trigger Plugin

I have a pipeline type job in my Jenkins. What I am trying to do is to run some pipelines with a parameter like release. For example, I want to run this pipeline for version 1.3.5. I prepared a pipeline code for that and tried to use Parameterized Trigger Plugin to make it parameterised. This plugin was working for normal type tasks but, I couldn't make it works with pipelines.
Here is my definition of the variable;
I can't access the variable I defined with the plugin. Here is the pipeline part which tries to access it;
....
build_tag = "${TAG}"
But, build_tag variable is always null. I tried env.${TAG} and ${env.TAG} but no result.
I defined String param named THIS_IS_TEST and was able to get the value with -
echo "${THIS_IS_TEST}"
Make sure that the plugin is updated

How can I create parameterized Jenkins job?

I want to use same job in different machine. But I don't want to change the configuration of the job each time. Can I pass the machine name label as parameter and run the job in different machine ? (Not simultaneously).
I want to pass parameters while running a job to the script which I have written in th configuration (batch script). Can we do that ?
Can I get a return value from a job and use it in next job?
Example criteria:
User needs to use different environments for executions.
1. Select jenkins project
2. Job -> Configure -> Select this project is parameterized check box.
3. Select Add parameter drop down - > String parameter
4. Define a string parameter (In my example I use environment variable as : BaseURL)
5.Now under build section initialize the mvn command user needs to execute.Here in this case I want to execute my jenkins build on a environment where I specify. So I should be able to execute my build in different environment each time with out changing the code.
My mvn command: I pass my environment url as a parameter (Using $ sign). This is based on user requirement.
clean test -Dcustomproperty="$BaseURL"
6. Apply and save your Jenkins project.
7. Now your project is parameterized. Then your project should have Build with parameters option.
8.Click Build with parameters link and enter your parameter (In this example my environment variable) and click build. Your jenkins job should run with the parameter.
NOTE: This build won't succeed unless the passing parameter is not utilized in the automation script. So script has to be modified to retrieve the passing variable.
String BaseURL= System.getProperty("customproperty");
Yes, you can pass a node label parameter with NodeLabel Parameter Plugin.
Yes, you can define parameters, as described, in Parameterized Builds and then use it in your script as an environment variable:
The parameter is available as environment parameters. So e.g. a shell ($FOO, %FOO%) or Ant ( ${env.FOO} ) can access these values.
This is not exactly a return value, but you can pass any parameter (with its value) to the downstream job with Parameterized Trigger Plugin.
Use parameterized Build plugin and NodeLabel Parameter Plugin

Jenkins Promoted Build Parameter Value

I have a jenkins job that runs some tests and promotes the build if all tests pass.
I then have a second job that has a 'Promoted build parameter' which is used for deployments.
THe idea is that the deply job should let you pick one of the prompted builds for deploying. The issue I'm having is that I can pick a promoted build, but I have not idea how I access information about the build.
I've named the build parameter
SELECTED_BUILD
And according to the docs this should then be available via the environment.
The problem is that it doesn't seem to be bound to anything.
If I run a build step to exectute this sheel script:
echo $SELECTED_BUILD
echo ${SELECTED_BUILD}
The values are not interpolated / set.
Any idea how I can access the values of this param?
Many Thanks,
Vackar
Inject the information as variable user jenkins plugin (eject evn variable).
while triggering parameterized build on other job, pass above variable as parameter to next job.

Resources