Jenkins: trigger other jobs trigger - jenkins

How can a job A trigger a job B, such that job B will poll its SCM and then decides wether the actual build would be started or not?
Here is my 'real world' setup: I have a job called GIT_PULL which is using Jenkins DSL to create child jobs depending on sub folders in the repository content. Those child jobs poll the SCM itself but with the option 'Polling ignores commits in certain paths' to ensure they were just triggered, when their sub path has changed.
The current state is that all the child jobs poll the SCM theirselves every H/5 minutes and run independently of their parent job GIT_PULL. However I need to know in GIT_PULL if after a SCM change all child jobs has run fine. But when I switch the polling in the child jobs off and trigger all child jobs in GIT_PULL, they will all run no matter if their repository sub paths has changed or not.
So how can I trigger all child jobs in GIT_PULL, waiting for their result and such that the child jobs will check SCM changes before they will actually run?

Yess - The Multijob Plugin will do the trick.
Within a MultiJob you can define downstream jobs to start but to Build only if SCM changes (that is the exact option name) occur in the downstream project.

Related

How to get manual trigger button for a jenkins job?

I have a downstream jenkins job(B) which now gets triggered automatically by upstream job(A) if it is stable. But I want a manual trigger button in the pipeline view for job B. If job A is stable job B should wait for manual trigger to start. I'm using jenkins freestyle project for creating jobs.
First you have to remove the downstream jobs from A. Follow the steps and disable first.
#goto the job B
#configure
#goto build triggers and uncheck the button
build after other projects are built
So afterwards Job B will not get start automatically. And now you can goto your pipeline view and see and edit.

Jenkins P4 plugin triggers, trigger by branch

I am using the "P4 Plugin" - https://wiki.jenkins-ci.org/display/JENKINS/P4+Plugin in Jenkins v2.32.1.
I would like to trigger specific jobs in Jenkins, depending on what path is changed in SCM.
For example if something changes in
//depot/branchA
Build job A. If something changes in
//depot/branchB
Build job B.
As far as I can tell the plugin is only set up to trigger every job in Jenkins that has "Perforce triggered build." (building both A and B jobs) Am I missing something? I am currently using SCM polling and trying to move to a more efficient system.
This understanding is based on reading the "Triggering" section of https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md
You may be defining too broad a workspace, and causing Jenkins to trigger on every submit. The client workspace associated with job A should only map //depot/branchA/..., and the workspace for job B should only map //depot/branchB/....
Jenkins polls for changes, and if it sees any, triggers any build that has a matching path. So if both jobs had a workspace that mapped //depot/... then submits to branchA or branchB would trigger both jobs.

Run jenkins job without triggering downstream jobs

I have a jenkins job with a couple of downstream jobs which are triggered upon the job finishing correctly.
There are times when I want to run the initial job without triggering the downstream jobs. Is this possible?
It sounds like the conditional build step plugin might be of help. You can configure it to trigger other jobs based on various conditions, like so:
Here, the conditional build step has been configured to run downstream-job if foo.txt exists in the current workspace.

Jenkins trigger a job only after one has completed and avoid parallel execution of jobs

I have two jobs in Jenkins: Job A that gets triggered on a commit and job B. Technically job B is triggered only after job A has been completed as job B is mentioned as a downstream of job A in the post build actions, but imagine this scenario:
Job A has been triggered by one commit and is running while the job B is still running from previous commit of job A, this is causing potential failures and complexity as both are running in parallel.
What is the best way to prevent both of them running in parallel?
These are the plugins I saw on jenkins wiki:
Build Blocker Plugin
Multijob Plugin
Still wanted to know the best course of action.
You can use the Multijob plugin for this and then both sub jobs will be wrapped in one job that is triggered by a commit.
You can avoid parallel execution of that job (in case of 2 commits in short time, the 1st commit will trigger the job, the 2nd will be 'pending')

How to trigger two job from single job in Jenkins

I have one main Job on Jenkins.
I also created two jobs:
One job for scm changes build
One for Scheduled Build
In both job I gave the same configuration file as well as workspace.
I just give the name of job different.
Now from the main job through script I'm triggering SCM changes build which is success.
Again from the main job through script I am triggering Scheduled Build which is success.
When both trigger is started from main job, as same time that is SCM changes and scheduled build.
I am getting error due to in both job I gave the same workspace.
How to decide through script from main job when Scheduled build is over then start SCM change build?
Trigger the SCM change build from the scheduled build instead of the main job, using the "Trigger / call builds on other projects" option in the main job's build steps.

Resources