Pipeline script for Build Trigger

4,706 views
Skip to first unread message

John Chandra

unread,
May 16, 2016, 5:54:13 PM5/16/16
to Jenkins Users
Hi All,

Is there any way to configure a build trigger using pipeline script in Jenkinsfile? We still want to trigger the build when a change is pushed to GitHub. Is that still possible using Jenkinsfile in Jenkins 2.0? I've been searching around but I couldn't find a way to get this done.

John

Craig Rodrigues

unread,
May 17, 2016, 12:29:10 AM5/17/16
to Jenkins Users

Michael Kobit

unread,
May 17, 2016, 10:02:31 AM5/17/16
to Jenkins Users
I think https://issues.jenkins-ci.org/browse/JENKINS-34005 is what you are looking for.

John Chandra

unread,
May 17, 2016, 11:35:16 AM5/17/16
to Jenkins Users, rod...@freebsd.org

Hi Craig, thanks for your response. That is not exactly what I was looking for. When we create a pipeline, there are some options available for Build Triggers. The problem is I can't find a way to set the trigger I need through Pipeline script like the way I set the Job Properties (e.g. This project is parameterized, etc). If I can do this, then I can put the commands in a Jenkinsfile on GitHub and let the GitHub organization scan control the build job creation.

John Chandra

unread,
May 17, 2016, 11:37:38 AM5/17/16
to Jenkins Users
Hi Michael, Thanks for your reference. So that means that there is an open issue regarding controlling the build trigger on Jenkins 2.0. Am I correct?

Michael Kobit

unread,
May 17, 2016, 11:37:27 PM5/17/16
to Jenkins Users

Based on what I can see on that issue, I believe that is the open issue you should follow.


--
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/95ab38d2-fbcc-4bad-bb0f-01acf7306d09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Chandra

unread,
May 18, 2016, 2:22:00 PM5/18/16
to Jenkins Users
I see. Thanks, Michael!

Michal Medvecky

unread,
Aug 11, 2016, 10:01:19 AM8/11/16
to Jenkins Users
I see that the related issue was resolved, but I still don't know how to add "Build when a change is pushed to GitHub" support to my Jenkinsfile.

Can anyone help me please?

Michal

John Engelman

unread,
Aug 12, 2016, 2:55:03 PM8/12/16
to Jenkins Users
I was able to get the branch to enable the trigger by adding the following to my Jenkinsfile:

properties([
    pipelineTriggers([
      [$class: "GitHubPushTrigger"]
    ])
  ])

I then manually executed a Branch Index on the parent job and the resulting PR builds had the trigger on push setting enabled.

Sebastian Gurlt

unread,
Jan 27, 2017, 4:58:21 AM1/27/17
to Jenkins Users
Hey,

I want to do the same with automatic time based builds, any hint how I could implement this ? :)

Greetings
Sebastian

Kevin Burnett

unread,
Jan 30, 2017, 12:12:00 AM1/30/17
to Jenkins Users
Sebastian, here's a snippet of a declarative Jenkinsfile pipeline showing a time-based (cron) trigger:

pipeline {
  triggers {
    // every 30 minutes during 9 hours each night
    cron('H/30 20,21,22,23,0,1,2,3,4 * * *')
  }
  agent { label 'docker' }
  environment {
    GIT_COMMITTER_NAME = 'jenkins'
    GIT_COMMITTER_EMAIL = 'jen...@jenkins.io'
  }
  stages {
    stage('setup') {
    .....
Reply all
Reply to author
Forward
0 new messages