Force Jenkins to run triggered Job on same Node - jenkins

I have a some Jobs running on jenkins that has several nodes.
In the past I forced all my jobs to run all on the same node.
Now for purpose of load distribution I would like to reduce this constraints.
But sometimes I need one Job that is triggered by another to run on the same node.
This triggered Job can be triggered by any job (with different parameters) but if this is triggered by a Job it should run on the same node.
e.g.:
Triggered Job = Job_T
Any Jobs: Job1, Job2, Job3
Node X: Run Job1 -> Job_T(Job1)
Node Y: Run Job2 -> Job_T(Job2)
Node X: Run Job3 -> Job_T(Job3)
Is this possible to configure in the Jenkins Jobs?

Parameterize your jobs if they are not already. Pass the parent job node label as parameter to the downstream (triggered) job

Related

Concatenated jobs in Jenkins

I have to solve the following problem:
I have a job A in Jenkis. In one of the stages another Job B is started by the "job build" command.
For Job A to finish, it needs to wait for Job B to finish.
The problem is that Job B does not start because it is waiting for Job A to finish.
I'm using pipeline script in all Jobs.
I imagined that using the command " build job: 'my Job', propagate: true, wait: true" Jenkins would start Job B and after completion of B, it would return to complete Job A
workflow example
I'm assuming you just have one executor configured in your Jenkins Server/Slave. Hence Multiple builds are unable to run at the same time, which causes your deadlock.
In order to increase the executor count follow the following instructions. If you are just using the master to build. Go to Dashboard > Manage Jenkins > Configure and increase the executor count.
If you have slaves go to Dashboard > Manage Jenkins > Manage nodes and clouds click on the edit icon on the Slave and increase the executor count(more than 1) for slaves.

Trigger multiple builds parallel at one fire in Jenkins Pipeline

Context
I have a few Jenkins pipelines which are based on the regex to select the matching jobs to run. The number of downstream jobs for each pipeline around 60.
So I have written down the declarative scripts to select these matching job then built it with Jenkins Build Plugin parallel. In general, it's something as below:
Finish deploy to A --> Pipeline A (master node)
->> 60 downstream jobs (slave nodes)
Finish deploy to B --> Pipeline B (master node)
->> 60 downstream jobs (slave nodes)
Finish deploy to C --> Pipeline C (master node)
->> 60 downstream jobs (slave nodes)
The master node is the server used to run Jenkins.
The slave nodes are the AWS EC2 instances used to run the task, my pool around 32 servers which can be used up to 180 tasks at once.
Expected
Let's say I have those pipeline triggered pipeline A, pipeline B, pipeline C in sequence then I expect the downstream jobs are triggered gonna be in the queue in sequence. It means first 60 jobs from A will be scheduled, built then so on pipeline B, pipeline C, given the slave executors are still free and available to use.
Observed
Even the AWS EC2 instances running no task (all available), the pipeline did not trigger all the jobs at one fire but part of its. It means a random number of jobs in pipeline A will be built first, then after a while, the rest will be built.
The pipeline script:
Stage('Integration Test Run') {
steps {
script {
matchingJobs = commonPipelineMethods.getTestJobs(venture_to_test, testAgainst)
parallel matchingJobs.collectEntries{downstreamJob-> [downstreamJob.name, commonPipelineMethods.buildSingleJob(this, downstreamJob)]}
}
}
}
def buildSingleJob(steps, downstreamJob) {
return {
def result = steps.build job: downstreamJob.fullName, propagate: false
steps.echo "${downstreamJob.fullName} finished: ${result.rawBuild.result}"
}
}
So I'm not sure if I need anything to config, setting up the pipeline script to get those downstream job running at one fire.
Could anybody please look into this and give me some suggestion? Thanks

How to get the status of child Jenkins Job from parent Jenkins job

I am currently running 2 Jenkins jobs where one Jenkins Job (Job A) calling another Jenkins Job (Job B) by using "when builds promote". Once it is approved manually, then Job B job will get triggered. After this step, I need the scenario like I would like to get status from Job B in Job A.
If my Job B fails then Job A should fail or vice versa. Any help!
You are missing the fundamentals of how Jenkins works. If an upstream job (job 1) is successful and the downstream job (job 2) fails, Jenkins is doing its job correctly by showing the actual statuses of the jobs (i.e., job 1 is green and job 2 is red).
If the upstream job fails then the downstream should never kick off in the first place, so you won't have to worry about that. This is how Jenkins was designed to work.

How to check if Jenkins node1 is free for the job, if not check for the node 2 and trigger the build on node2?

I have a job which has the node name as a parameter(Made possible using NodeLabel Parameter Plugin).
I will trigger the job always with node1 as the parameter. I want the job to see node 1 is online and free(no other builds are going on in that node). If node1 is free run this job on node1 else this job should find a free node and run it on that(ie; trigger this same job in other node (eg; node2) if node1 is not free).
How can I do that? How can I know whether a node is free? I don't want my job to be waiting for a node to complete other builds.
Have the same label name on both agents (for example "windows") and have your job run with label "windows". It will run in a little different manner. In this case when you run that job with target label "windows", jenkins will send the request to both nodes but jenkins will run the job on the agent which will respond first.

Jenkins jobs on slave servers

I have many Jenkins Jobs that I need to run on every Build,
At present time I have 4 slave servers.
I would like the jobs to run in parallel as much as possible, hence I defined the jobs as follow:
Execute concurrent builds if necessary - Disabled
Restrict where this project can be run - Enabled with the following values SalveLinux1HT||SalveLinux2HT||SalveLinux3HT||SalveLinux4HT
To my understanding if Job A and B are triggered at the same time, one should use 1HT and the other should use 2HT and they can run in parallel
however Jenkins build job A on all 4 slaves and only after it's finished he will build job B on all 4 slaves
This is the opposite of my goal
Any ideas?
Thanks in advance
You can use
Build Flow Plugin
You can find both installation and configuration instructions of this plugin at the above mentioned link.
If you want to run any jobs in parallel you can use following scripts:
parallel (
// job A and B will be scheduled in parallel.
{ build("jobA") },
{ build("jobB") }
)
// jobC will be triggered after jobs A and B are completed
build("jobC")

Resources