Command line acccess to build actions in muti branch pipeline

9 views
Skip to first unread message

BCT Roel de Wildt

unread,
Apr 1, 2020, 7:08:41 AM4/1/20
to jenkins...@googlegroups.com

Hello,

 

In previous versions of Jenkins LTS there was a jenkins-cli.jar which I used to trigger a build job. Now with the latest (2.222.1) I can’t find how to do the build jobs on a scheduled base. Where one is shedules at 19:00, the other on 20:30, etc… They can’t run at same time due resources limits. What is the best option to execute a single build job in a multi branch pipeline?

 

Kind regards,

Roel de Wildt
Software Engineer

 

Gianluca

unread,
Apr 1, 2020, 7:17:17 AM4/1/20
to Jenkins Users
Hi,
we have a similar issue and we use a combination of trigger cron command with "H" (if instead of * into cron syntax, you put "H" then Jenkins treats it special)
"The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project."

But also that's is not sufficient in cases the pipeline takes more than an hour (as in our case), hence we add on top of this the usage of LockableResources and we created a resource that we lock in the stages of the pipeline we know we can't run at the same time because of constraints.


So, a combination of both ... does the tricks for us and I think it should work as well for you too.

Cheers,
Gianluca

BCT Roel de Wildt

unread,
Apr 1, 2020, 9:09:19 AM4/1/20
to jenkins...@googlegroups.com

Hi,

 

I have looked at it but it seems only possible if I change our Jenkinsfile within each project stored in svn within the branches of it. And I can’t see where to put the cron entry in the multi branch pipeline. I have only the following options (… 12 hours, 1 day, 2 days, etc… ) in “Periodically if not otherwise run” in the triggers section.

 

That means I can’t control the time it will be executed.

 

Alternative:

I can execute a scheduled curl program which triggers the “trunk” successfully, but the “branches/2019/trunk” gives a http 404 error.

 

Kind regards,

Roel de Wildt
Software Engineer

 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c96a2c92-9eb4-4e3e-9323-63c829418bc3%40googlegroups.com.

Gianluca

unread,
Apr 1, 2020, 9:25:27 AM4/1/20
to Jenkins Users
Hi,
I'm not sure I'm following you ... or maybe we are using different ways to write our pipeline.
So, to be more explicit ... this is what we have in our pipeline:

pipeline {
triggers {
// runs every two hours
cron('H H/2 * * *')
}

That is a Multibranch project (to be precise we use GitHub, not sure if what I see maybe related to Git plugin itself) and what happens due to the "H" special case is that each branch will have a different starting hour and minutes that actually spread them over the time.
In that case you achieve the fact that there will never be two jobs starting at the same time.
Now, you can still have them overlap after they started.
To avoid that they run a certain stage at the same time we use locks:

steps {
// lock not usable in declarative pipeline due to JENKINS-43002
script { lock(label: resourceLabel, quantity: 1) {

With the above, what you achieve is that only and only one job at the time can run what's inside the script block.

We both cron and locks ... you spread your jobs across day hours and you are guaranteed that they run sequentially when the reach a part that can't be run by two jobs at the same time. And that works across branches.

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

BCT Roel de Wildt

unread,
Apr 3, 2020, 8:34:21 AM4/3/20
to jenkins...@googlegroups.com

Hi,

 

My thanks for the solution you gave me.

 

I have implemented this solution with the cron entry and the resource lock. Now the pipelines are triggered at 19:00 and executed sequential, but my concerns are when we create a branch of them that they are also executed daily. That is not what I want to happen. It should be a manual action to build those branches.

 

Because the Jenkinsfile is stored in our svn project and the trigger is also in the Jenkinsfile. I think when I make a branch for a new release version of the product it would also executed at 19:00. How can I prevent this from triggering without adjusting the Jenkinsfile for every branch?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f880bc76-6669-401b-b1b4-b588e4c794df%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages