Trigger workflow on Github push - Pipeline plugin

2020-05-20 02:30发布

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?

7条回答
在下西门庆
2楼-- · 2020-05-20 03:19

Before I start, I would like to emphasize that I had no previous experience with Jenkins so far, so there might be a bunch of better solutions out there.

What I wanted to achieve in a nutshell:

  • After every push made to a Bitbucket repo(test2), on every branch,
    pull and build another Bitbucket repo(test1), from an identical
    branch name and right after that, build test2 using test1 as a
    dependency.

How I managed to achieve that?

  • I started a new job with type 'Multibranch Pipeline'
  • I added the following Jenkinsfile to test2:

pipeline {
    agent any
    stages {
        stage('build') {
            steps {
                dir('test1') {
                    git branch: BRANCH_NAME, url: 'git@bitbucket.org:user/test1.git', credentialsId: 'credentials_id'
                }
                sh('build_process')
            }
        }
    }
}

  • I come across the issue that you can't set up a Bitbucket hook for pipelines

  • I added Bitbucket Branch Source Plugin to Jenkins

  • I selected Bitbucket at 'Branch Sources' when setting up the job

  • I added credentials and put a checkmark to Auto-register webhook

  • Under 'Scan Multibranch Pipeline Triggers' I put a checkmark to Periodically if not otherwise run, with an interval of 1 min

  • I added a webhook to my Bitbucket repo

  • I updated all my plugins, restarted Jenkins and it's ready to go

Other plugins I have installed: Bitbucket Plugin, Pipeline plugin. Hope this helps for somebody, I did manage to solve it this way after hours of struggling without the Bitbucket Branch Source Plugin.

查看更多
登录 后发表回答