How to disable jobs of type Multi-branch?

212 views
Skip to first unread message

Idan Adar

unread,
May 30, 2017, 3:36:22 PM5/30/17
to Jenkins Users, jgl...@cloudbees.com
I thought this would be possible after the fix in https://issues.jenkins-ci.org/browse/JENKINS-27299, but apparently not so... Hence asking here.

Assuming in a Jenkinsfile, that is run as part of a multi-branch type job, I decide to disable some jobs, e.g:

post {
 failure
{
  script
{
   
def job = Jenkins.instance.getItem("some-job-name"); job.disable();
 
}
 
}
}

If this actually works, how could I then re-enable this job given there is no button in the UI to enable (or even disable) a multi-branch job?

Stephen Connolly

unread,
May 30, 2017, 4:47:52 PM5/30/17
to jenkins...@googlegroups.com
On Tue 30 May 2017 at 20:36, Idan Adar <id...@adar.me> wrote:
I thought this would be possible after the fix in https://issues.jenkins-ci.org/browse/JENKINS-27299, but apparently not so... Hence asking here.

Remove the branch from being discovered... (then it will be an orphaned branch and disabled until eligible for removal according to the orphaned branch strategy you configured)

Or delete the branch.


Assuming in a Jenkinsfile, that is run as part of a multi-branch type job, I decide to disable some jobs, e.g:

post {
 failure
{
  script
{
   
def job = Jenkins.instance.getItem("some-job-name"); job.disable();
 
}
 
}
}

If this actually works, how could I then re-enable this job given there is no button in the UI to enable

Well you'd commit to the branch again and then the next build of that branch would enable it... oh but you cannot have another build because the branch is disabled...

This is in part why the functionality you are looking for is not present. Once you disabled the job it would be stuck there forever.
(or even disable) a multi-branch job?

--
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/57001001-e365-4c14-b901-5ee4f8417bb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Idan Adar

unread,
May 30, 2017, 10:59:23 PM5/30/17
to jenkins...@googlegroups.com
Deleting a branch is definitely not an option.

The actual scenario here is that when end-to-end tests are run, if they fail then I want to disable all other jobs (why? Because that's the task I was handed... I don't necessarily agree with this...). 

In my case those other jobs are of type multi branch.

I can't delete the branch in question because it is the develop branch... :)

So I'm just looking to programmatically disable such jobs and then how to manually enable them (after the issue in the test failure was resolved).

 

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/CwXkESYhfDs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMxORekN_hv_SAuJ2LsaCtYUqZ%2BOr7BCT%2BRQFkEbwktCww%40mail.gmail.com.

Idan Adar

unread,
May 30, 2017, 11:19:02 PM5/30/17
to Jenkins Users
To disable, can I point to a branch like so?
def job = Jenkins.instance.getItem("job-name/branch-name"); job.disable();

And then to enable, maybe it could be achieved also programmatically?
def job = Jenkins.instance.getItem("job-name/branch-name"); job.enable();


Stephen Connolly

unread,
May 31, 2017, 9:03:18 AM5/31/17
to jenkins...@googlegroups.com
no.

What you really want to do is not have those branches build automatically.... effectively you want to turn the multbranch source to be something likeInline images 1
or (assuming you want master to still build automatically)
Inline images 2

Should be possible to configure that by groovy or a plugin

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/63a5e368-ff1a-4898-b86f-1eee9536961c%40googlegroups.com.

Idan Adar

unread,
May 31, 2017, 9:17:40 AM5/31/17
to Jenkins Users
I actually do want these to build automatically. I control what then happens in the jenkinsfile...


On Wednesday, May 31, 2017 at 4:03:18 PM UTC+3, Stephen Connolly wrote:
no.

What you really want to do is not have those branches build automatically.... effectively you want to turn the multbranch source to be something likeInline images 1
or (assuming you want master to still build automatically)
Inline images 2

Should be possible to configure that by groovy or a plugin
On 30 May 2017 at 20:19, Idan Adar <id...@adar.me> wrote:
To disable, can I point to a branch like so?
def job = Jenkins.instance.getItem("job-name/branch-name"); job.disable();

And then to enable, maybe it could be achieved also programmatically?
def job = Jenkins.instance.getItem("job-name/branch-name"); job.enable();


--
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.

Stephen Connolly

unread,
May 31, 2017, 10:00:50 AM5/31/17
to jenkins...@googlegroups.com
On 31 May 2017 at 14:17, Idan Adar <id...@adar.me> wrote:
I actually do want these to build automatically. I control what then happens in the jenkinsfile...

multi-branch is strongly opinionated. One of the core opinions is that branches are independent.

it sounds like what you are trying to do is significantly more reliant on repository cohesive state.

I would suggest taking a different approach. In any case, the stuff you are likely trying to do is not something that is "permitted" from a Jenkinsfile as there are too many security risks. As such you will probably have to write a plugin.

I recommend re-thinking your use-case and requirements if you want to do something off-the-shelf without having to write a Jenkins plugin. 
 
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1e9347b6-b304-4c74-bb33-e3c119b9ac06%40googlegroups.com.

Idan Adar

unread,
Jun 1, 2017, 4:53:23 AM6/1/17
to Jenkins Users
Thanks for the suggestions Stephen. I'd like to try a couple more ideas...

Is it possible to modify a global variable? What are my options to deal with variables cross-jobs?

Idan Adar

unread,
Jun 1, 2017, 1:23:13 PM6/1/17
to Jenkins Users
I ended with updating a file in a repo if the tests fail.
Any job that then tries to run will first check for the contents of the file, if it's not what it should be the job will exit.
Reply all
Reply to author
Forward
0 new messages