I have a question for downstream job in jenkins.
I want to use directly the value of a predefined parameters from upstream job in the git parameter of a downstream job.
How is this done?
Yes , just add the parameters to the downstream job. And it will do the trick
Related
I have an old classic ui jenkins pipeline. now i need this pipeline to be triggered on the completion of other pipelines. And get the upstream pipeline information in this old pipeline.
I know how to set the upstream build trigger in the jenkins pipeline. However i cannot find a way to get the upstream build information (eg, project name, git commit).
When i output the env variables in downstream pipeline, i can only see the BUILD_CAUSE=UPSTREAMTRIGGER which is not useful for me.
Trigger Downstream Job With Parameters
The old job would need to be updated to be parameterised, then you can pass the required information as parameters when you build the downstream job.
Example:
build job: "DOWNSTREAM_JOB_NAME",
parameters: [string(name: 'upstreamJobName', value: env.JOB_NAME),
string(name: 'upstreamJobVar', value: "${upstreamJobVar}"]
Trigger Downstream Job Without Parameters
When parameters are not being send from triggering upstream job, then we can get some of the upstream information in the downstream job like this:
currentBuild.upstreamBuilds[0].projectName
All available methods for upstreamBuilds information can be found here
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.
I have a freestyle job in Jenkins and would normally pass parameters to another freestyle job using the Predefined parameters option.
example:
PROJECT=Myproject
PATH=/depot/workspace/
Previously I could access the above values through the KEY in the downstream job through the environment by using ${PROJECT} OR ${PATH}.
My problem now is that I have a pipeline job that needs to access the above values but when using ${PROJECT} OR ${PATH} it does not work.
So, in general how I want it to work is have the freestyle job run first and pass the parameters to the downstream pipeline job.
You might need to use "${params.PROJECT}" in your pipeline to access the parameters.
I have a multijob A, it has some downstream jobs (subA1, subA2, ...). Each downstream job has its own parameters.
When I run job A, all parameters of job A are passed to downstream jobs but their own parameters of downstream jobs (subA1, subA2, ..) does not appear.
How can I make subA1, subA2, ... get their own params ?
I can make a downstream job with the DSL plugin for Jenkins:
https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-reference#downstream
How can I make an upstream job (same thing...just specified in a difference place)?
In the UI, it's under Triggers: "Build after other projects are built".
Currently that's not possible. The Job DSL plugin generates the configuration XML used internally by Jenkins. The upstream job is not part of that XML, Jenkins generates the information at runtime. So if you specify the upstream in a job, what Jenkins does is setting the downstream in that upstream job and persists that. And that's something that the Job DSL currently can not do.
I define specific jobs that I want to be the upstream and define downstream jobs since that is specified in Jenkins DSL. This has worked well for me.
upstream method is available since Jenkins 1.33:
job('example') {
triggers {
upstream('some-upstream-job-name')
}
}
See https://YOUR.JENKINS.DOMAIN/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.upstream