I have a Jenkins job that accepts NODE as parameter. I want to trigger the job from Jenkins pipeline using "build step" plugin. Passing the value as string is not working as the job is landing on random node
Here is my pipeline code. RepairAgentWorkspace expect NODE_TO_REPAIR to be a node type.
node{
build job: 'RepairAgentWorkspace',
parameters: [string(name: 'NODE_TO_REPAIR', value: "git_agent")]
}
Above code triggers the job but it's not landing on "git_agent" agent. Any idea how can we pass node as param?
Related
I have a pipeline which triggers a jenkins freestyle job.
How to access the pipeline name from the freestyle job.
I tried using ${BUILD_CAUSE} but it shows the value as UPSTREAMTRIGGER.
How to get the pipeline name?
JOB_NAME may contain the name of the job that you're after, unless it was triggered by an upstream job.
See a list of generic Jenkins environment variables that are available in most builds. The best way to find out what environment variables are available is to run sh 'printenv' in the steps.
If you need the name of the upstream job in a downstream job, I'd suggest setting a parameter on the downstream job and then referencing it when you trigger the job.
e.g. Upstream Pipeline job:
...
step {
build job: 'freestyle-downstream-job', parameters: [
string(name: 'upstream_job_name', value: "${JOB_NAME}")
]
}
...
How do you pass parameter into a pipeline script but not make it a parameterized build in the jenkins UI.
This script will get used in more then one place and I would like to be able to pass some values into the script but not make it a parameterized build where the users can set them.
In its simplest form, here's how you would do that.
The job that you want to pass parameters to looks like this (scripted pipeline). Let's call this job "ParamJob".
print "Parameter passed: ${params.myParam}"
The job that you would kick "ParamJob" off with would look like this ..
build job: 'ParamJob' , parameters:[
string(name: 'myParam', value: 'Test parameter')
]
And the output of "ParamJob" is
Parameter passed: Test parameter
I am using a parametrized job to trigger pipeline jobs job1,job2 and job3. My intention is that by default job1,job2,job3 should run on node "A" and whenever I use parametrized job, and select node "B" manually then all downstream jobs i,e job1,job2 and job3 should run on the node "B".
I used nodelabel parameter plugin but only parent job will run accordingly as selected parameter but downstream jobs are not triggered on the selected parameter in the parent job.
Make a job parameter for job1, job2 and job3. Use this parameter for nodelabel. Make the default for this parameter nodeB. When you start the job with the parametrized job set the parameter nodeA as seen below:
build job: 'job1', parameters: [[$class: 'StringParameterValue', name:'nodeA']]
I'm not able to build a job from jenkins pipeline passing a variable for job name. Please find below the code snippet. If I replace ${service} with 'microservice' it will trigger the job
service = 'microservice'
echo "TESSSSSSSSTTT ${service}"
build(job: "'${service}'", parameters: [string(name: 'ENVNAME', value: 'uat')])
The error faced is:
[Pipeline] echo
TESSSSSSSSTTT microservice
[Pipeline] build
[Pipeline] End of Pipeline
ERROR: No item named 'microservice' found
Finished: FAILURE
I'm using this method because I want to hit a build command for all the microservices passing the names with multi-line string parameter, finally I want to set this build into a loop.
I assume your job is not called 'microservice' in Jenkins but microservice (without the ticks).
So change your build line to not include single quotes after the double quote:
build(job: "${service}", parameters: [string(name: 'ENVNAME', value: 'uat')])
Did some simple test with my jenkins instance and was able to call a job by setting the service variable to an existing job name.
I have 3 jobs building in pipeline job as below
node('master') {
stage ('first')
parallel firstBranch: {
build 'job1'
build 'job2'
}
stage ('second')
build 'job3'
}
My job2 can take parameters and it should be passed from job1. How can I do that in pipeline?
I cannot use Parameterized Trigger Plugin as I don't want to trigger one job from another.
I want a way to pass the parameters from one job1 to job2 inside pipeline project.