Declarative Pipeline: Add trigger only on when condition

60 views
Skip to first unread message

Sverre Moe

unread,
Oct 22, 2021, 6:17:46 AM10/22/21
to Jenkins Users
We have a branch in projectA called CICD.
This branch we want to be triggered automatically after the master branch has built.
However we do not want user branches of the CICD to be triggered automatically.

Is it possible to avoid configuring a trigger if the branch is not CICD?

This is probably not possible, but would be very useful.

    triggers {
      upstream 'projectA/master'
      when {
        branch 'CICD'
      }
    }

Victor Martinez

unread,
Oct 27, 2021, 3:25:01 AM10/27/21
to Jenkins Users
I'm not sure if I understood correctly what user branches of the CICD mean in this particular case, can you clarify it?
Some other questions:
- Are the master and CICD branches part of the same projectA? 
- If so, how do users interact with the project?

As far as I see the upstream trigger option allows to listen for changes in some other projects.

Will it work if you split two pipelines instead?

Pipeline for the master branch 

or even a multibranch pipeline if needed, then you can exclude  the CICD branch to be built.

Pipeline for the branch CICD

or event a multibranch pipeline if needed, then you can exclude everything but the CICD branch.

    triggers {
      upstream("projectA/master'")
    }


Cheers

Sverre Moe

unread,
Oct 27, 2021, 7:40:43 AM10/27/21
to Jenkins Users
User branches are like
origin/username/CICD
Official branches are origin/CICD og origin/master

All part of the same project.
CICD branch has a different Declarative Pipeline for CICD release build and deployment.
Same goes for user branches that are based on this CICD branch.

All other branches have our standard Scripted Pipeline.
So we have already splitt different pipelines for these.

When all branches based on CICD are building, we don't want to build release and deploy from user branches of it, only the origin/CICD.
I wanted to avoid username/CICD being automatically triggered and built when origin/master had built. It should only trigger on origin/CICD.

Björn Pedersen

unread,
Nov 19, 2021, 6:19:02 AM11/19/21
to Jenkins Users
You can't do it on the triggers level ( the trigger config only can affect the next run, as the job is already triggered), but you can wrap the whole work in the pipeline in a when, 
so if the  branch is a  userbranch this run is mostly a do-nothing.

Björn

Reply all
Reply to author
Forward
0 new messages