Jenkins build multibranch pipeline from another multibranch pipeline - jenkins

I have Jenkins setup with 2 multibranch pipeline which depend on each other let say multibranchPipelineA and multibranchPipelineB. I would like a job from multibranchPipelineA to build specific branch in multibranchPipelineA and wait the build to finish
I have tried use below from multibranchPipeleA Jenkinfile
stage('Build MiniApp Libs') {
steps {
build(
job: "../multibranchPipeleB/master",
propagate: true,
wait: true
)
}
}
But always receive No item named ../multibranchPipeleB/master found.
If I use single pipeline, let's say pipelineB, then the below work
../pipelineB
How can I build specific branch multibranchPipeline from another multibranchPipeline jobs? and wait the build to finish?

To build another multibranchPipeline you do not need .. before its name. So in your case just use:
job: "multibranchPipeleB/master"

Related

Can I set up dependency builds in Jenkins similar to TeamCity?

I have not found information about that, I want to trigger build but before it executes, I want it to trigger some other pipelines and wait for a file created by these other pipelines to pass to a main Pipeline, can I do this in Jenkins?
You can, yes, in multiple ways depending on your actual use case.
The simplest way would be to create the job you want to call and then add a step for calling that job, copy artifacts from the job and then continue with the pipeline.
Using Jenkins Build step:
stage ('Child job') {
steps {
build(job: 'foo', wait: true, propagate: true, parameters: [parameters_list])
}
}
The parameter wait makes it so your pipeline waits for the child to complete run before continuing and propagate means that the result of the job is shown in the parent pipeline as well. The parameters section is needed only if your child job requires parameters. See the parameter types in the Build step documentation.
You can also use the Jenkins pipeline snippet generator to create the call properly in your own Jenkins instance.
To get any build artifacts from the child job, the easiest way to go is to use the Copy Artifact plugin. You'll need to archiveArtifacts in the first job and then
copyArtifacts fingerprintArtifacts: true, projectName: 'foo', selector: lastCompleted()
When the artifacts are needed.

Build a Jenkins pipeline (job) from another repo on another branch

What I am trying to do doesn't seem so complex but not so easy, but what I've read by now seems to make it look like I am launching rockets.
Basically let's say I have
my-deploys-repo with branches: master, develop
my-tools-repo with whatever branches
Inside my-tools-repo I have: Jenkinsfile-push-events ( jenkins pipeline )
Inside my-deploys-repo I have ON DEVELOP BRANCH: Jenkinsfile-deploy (which also gets some params, if it matters )
How can I trigger Jenkinsfile-deploy job from my-deploys-repo's develop branch FROM Jenkinsfile-push-events on my-tools-repo?
I understood that normally I'd do something like (inside Jenkinsfile-push-events)
stage('Deploy') {
steps {
script {
build job: '../my-deploys-repo/Jenkinsfile-deploy'
}
}
But it laying on another branch seems like a problem.
A Job in Jenkins has its definition in its properties and that already includes Jenkinsfile, so you cannot trigger a "Jenkinsfile" without defining a Job that uses that Jenkinsfile first.
If you have two branches, you need a Multibranch Pipeline job.
Let's say you created a new Multibranch Pipeline job — say MyJob is its name — that is configured to use your repo (my-deploys-repo.git) and your path to Jenkinsfile (Jenkinsfile-deploy.groovy). You can then trigger that job by:
build job: "MyJob/develop", wait: false, propagate: false,
parameters: [
string(name: 'PARAM_1', value: "1"),
string(name: 'PARAM_2', value: "maybe"), //etc.
]

Triggering a multibranch pipeline job from an other multibranch pipeline

I have a scenario where but I have 2 projects (A and B), both are configured in Jenkins with multibranch pipeline jobs, problem is that Project B depends on Project A.
So I find that some times when I check in code in Project A, I also need to build ProjectB once A was built. Now before I started investigating pipeline builds, I'd have a job per branch and then trigger in Jenkins the appropriate job for Project B for the appropriate branch.
What I'd like to set up in a Jenkinsfile so that when ProjectA/develop executes it then triggers the multibranch pipeline job for ProjectB and the same branch.
I have:
stage ('Trigger Tenant Builds') {
build job: "ProjectB/${branch}", wait: false
}
But my ProjectA pipeline fails with:
ERROR: No parameterized job named ProjectB/develop found
Any ideas?
I've resolved this now. What I am doing is defining an upstream trigger in project B's Jenkinsfile:
pipelineTriggers([
upstream(
threshold: hudson.model.Result.SUCCESS,
upstreamProjects: "/ProjectA/" + env.BRANCH_NAME.replaceAll("/", "%2F")
)
])

Jenkins pipeline groovy

Below is my simple jenkins pipeline groovy script by which it will create a pipeline with these 2 stages and the jobs we want to build,I want the job names in that for build and code analysis should get updated in the script under job configuration everytime by taking the data from the UI where the user will just provide the build jobname and code analysis jobname using Eclipse -
jenkinsfile script :-
stage('Build'){
build job: 'job1'
}
stage('Code_Analysis'){
build job: 'job2'
}
While your question is a bit vague, I guess the problem is that your Jenkinsfile does not include the node statement:
node {
stage('Build'){
build job: 'job1'
}
stage('Code_Analysis'){
build job: 'job2'
}
}
So you want to pass job name as parameters. You can use string parameter e.g. JOB1 & JOB2. Then pass that to build job as it is. No need of curly braces or inverted commas like shown below-
stage('Build'){
build job: JOB1
}
stage('Code_Analysis'){
build job: JOB2
}
I suppose the job name can be utilised using ${name} variable in jenkins pipeline

How can I pass parameters from a job to the other job when both the jobs are building inside a pipeline?

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.

Resources