Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger workflow on Github push - Pipeline plugin - Multibranch configuration

We are using the pipeline plugin with multibranch configuration for our CD. We have checked in the Jenkinsfile which works off git.

git url: "$url",credentialsId:'$credentials'

The job works fine, but does not auto trigger when a change is pushed to github. I have set up the GIT web hooks correctly.

Interestingly, when I go into a branch of the multibranch job and I click "View Configuration", I see that the "Build when a change is pushed to Github" is unchecked. There is no way to check it since I can not modify the configuration of the job (since it takes from parent) and the same option is not there in parent.

Any ideas how to fix this?

like image 515
Punit Agrawal Avatar asked Mar 03 '16 19:03

Punit Agrawal


3 Answers

For declarative pipelines try:

pipeline {
    ...
    triggers {
        githubPush()
    }
    ...
}

For me this enables the checkbox "GitHub hook trigger for GITScm polling", but polling is not actually required. This requires the GitHub plugin.

like image 103
Russell Gallop Avatar answered Nov 27 '22 00:11

Russell Gallop


I found a way to check the checkbox "Build when a change is pushed to Github".

This line did the trick:

properties([pipelineTriggers([[$class: 'GitHubPushTrigger'], pollSCM('H/15 * * * *')])])

I think the polling is needed to make it work. Would be nice if no polling is needed.

Here's a Jenkinsfile example with this implemented:

#!/usr/bin/env groovy

node ('master'){
    stage('Build and Test') {
        properties([pipelineTriggers([[$class: 'GitHubPushTrigger'], pollSCM('H/15 * * * *')])])
        checkout scm
        env.PATH = "${tool 'Maven 3'}/bin:${env.PATH}"
        sh 'mvn clean package'
    }
}
like image 39
Max Avatar answered Nov 27 '22 01:11

Max


For declarative pipelines, try this:

pipeline {
    agent any
    triggers {
        pollSCM('') //Empty quotes tells it to build on a push
    }
}
like image 26
DarkHark Avatar answered Nov 27 '22 02:11

DarkHark