How to set Multibranch Pipeline Trigger interval via Jenkinsfile?

882 views
Skip to first unread message

Yuri Govorushchenko

unread,
Jul 26, 2017, 7:42:55 PM7/26/17
to Jenkins Users
Hello,

I have a Multibranch Pipeline job and would like to programatically set its property found in UI at Scan Multibranch Pipeline Triggers -> Periodically if not otherwise run -> Interval. Ideally I'd like to do it in a scripted Jenkinsfile used to define the job. Maybe it can be somehow achieved via properties step? It seems to be a property of
CloudBees Folders Plugin but I couldn't figure out how it can be modified without a UI.

Thanks.

Ramanathan Muthaiah

unread,
Jul 26, 2017, 11:03:19 PM7/26/17
to Jenkins Users
We are on the same boat . . . would be interested to know how this can be done; if you hit upon the solution, pls do share here.

/Ram 

Stephen Connolly

unread,
Jul 27, 2017, 7:59:23 AM7/27/17
to jenkins...@googlegroups.com
Cannot be done from a Jenkinsfile.

You can do via the groovy console with something like

for (var f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class) {
  if (f.parent instanceof jenkins.branch.OrganizationFolder) {
    // managed by org folder, leave alone
    continue;
  }
  // addTrigger will replace an existing one
  f.addTrigger(new com.cloudbees.hudson.plugins.folder.computedPeriodicFolderTrigger("1d"));
}

--
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/ace70cd8-afa6-4966-a82c-e449cad3eeef%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Yuri Govorushchenko

unread,
Jul 27, 2017, 12:34:41 PM7/27/17
to Jenkins Users
Thank you Stephen! After fixing typos it worked for me from Script Console:

for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) {
  if (f.parent instanceof jenkins.branch.OrganizationFolder) {
    // managed by org folder, leave alone
    continue;
  }
  // addTrigger will replace an existing one
  f.addTrigger(new com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger("1d"));
}

Maybe in the future I'll be able to somehow incorporate this code into a JobDSL seed job to fully automate the definition of my multibranch job.

On Thursday, July 27, 2017 at 2:59:23 PM UTC+3, Stephen Connolly wrote:
Cannot be done from a Jenkinsfile.

You can do via the groovy console with something like

for (var f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class) {
  if (f.parent instanceof jenkins.branch.OrganizationFolder) {
    // managed by org folder, leave alone
    continue;
  }
  // addTrigger will replace an existing one
  f.addTrigger(new com.cloudbees.hudson.plugins.folder.computedPeriodicFolderTrigger("1d"));
}
On 26 July 2017 at 20:03, Ramanathan Muthaiah <rus.c...@gmail.com> wrote:
On Thursday, July 27, 2017 at 5:12:55 AM UTC+5:30, Yuri Govorushchenko wrote:
Hello,

I have a Multibranch Pipeline job and would like to programatically set its property found in UI at Scan Multibranch Pipeline Triggers -> Periodically if not otherwise run -> Interval. Ideally I'd like to do it in a scripted Jenkinsfile used to define the job. Maybe it can be somehow achieved via properties step? It seems to be a property of
CloudBees Folders Plugin but I couldn't figure out how it can be modified without a UI.

We are on the same boat . . . would be interested to know how this can be done; if you hit upon the solution, pls do share here.

/Ram 

--
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.
Reply all
Reply to author
Forward
0 new messages