github-integration-plugin icon indicating copy to clipboard operation
github-integration-plugin copied to clipboard

Help needed to support Github Organization multi-branch pipeline

Open syl20bnr opened this issue 7 years ago • 5 comments

Discussion started on PR thread: https://github.com/KostyaSha/github-integration-plugin/pull/118#issuecomment-307388477

I've got the plugin to work with GitHub organization multi-branch pipelines but jobs are executed twice. One time by multi-branch integration and one time by the github-integration plugin.

I would like to handle all the triggers with the github-integration plugin instead of the "built-in" triggers.

I would need some guidance about the possibility to unregister the webhooks installed by the multi-branch pipeline when the job is created. Does someone have some pointers about this ?

syl20bnr avatar Jun 12 '17 14:06 syl20bnr

You don't need unregister hooks in repository, trigger in job should have ability to ignore incoming hook. Could you give links to plugins that you are using?

KostyaSha avatar Jun 12 '17 17:06 KostyaSha

Here is an example pipeline I use for testing. The idea is to be able to have multiple commit contexts and be able to trigger them via messages in the PR thread.

def createCommitStatus(String context) {
    step([
            $class       : 'GitHubPRStatusBuilder',
            statusMessage: [content: "Build #${env.BUILD_NUMBER} started"],
            context: context
        ])
}

def setCommitStatus(String context, String state) {
    step([
            $class    : 'GitHubPRBuildStatusPublisher',
            context   : context,
            state     : state,
            statusMsg : [content: 'Build #${BUILD_NUMBER} ended'],
            unstableAs: 'FAILURE'
        ])
}

pipeline {
    agent any
    triggers {
        // I added this symbol to github-integration plugin
        ghprtrigger spec: '', triggerMode: GitHubPRTriggerMode.HEAVY_HOOKS,
        events: [[$class: 'GitHubPRCommentEvent', comment: '.*/ci\\W+check\\W+all.*'],
                 [$class: 'GitHubPRCommitEvent']]
    }
    options {
        // I added this symbol to github-plugin (fictitious url here)
        githubUrl('https://github.com/myorg/jenkins-pipeline-test')
        buildDiscarder(logRotator(numToKeepStr: '100'))
    }
    environment {
        CHECK_ONE_NAME = "first_check"
        CHECK_ONE_RESULT = 'FAILURE'
        CHECK_TWO_NAME = "second_check"
        CHECK_TWO_RESULT = 'FAILURE'
    }
    stages{
        stage('stage1'){
            steps {
                script { printInfo() }
            }
        }
        stage('CommitChecks') {
            steps {
                parallel (
                    "firstTask" : {
                        node('api_pr_quick_checks') {
                            script { printInfo() }
                            script { createCommitStatus("${CHECK_ONE_NAME}") }
                            sh 'sleep 10'
                            script { CHECK_ONE_RESULT = 'SUCCESS' }
                        }
                    },
                    "secondTask" : {
                        node('api_pr_quick_checks') {
                            script { printInfo() }
                            script { createCommitStatus("${CHECK_TWO_NAME}") }
                            sh 'sleep 10'
                            script { CHECK_TWO_RESULT = 'SUCCESS' }
                        }
                    }
                )
            }
        }
    }
    post {
        always {
            script { setCommitStatus("${CHECK_ONE_NAME}", "${CHECK_ONE_RESULT}") }
            script { setCommitStatus("${CHECK_TWO_NAME}", "${CHECK_TWO_RESULT}") }
        }
    }
}

List of all plugins we use:

ace-editor:1.1
ansicolor:0.5.0
ant:1.5
antisamy-markup-formatter:1.5
authentication-tokens:1.3
aws-credentials:1.20
aws-java-sdk:1.11.119
blueocean-autofavorite:1.0.0
blueocean-commons:1.0.1
blueocean-config:1.0.1
blueocean-dashboard:1.0.1
blueocean-display-url:2.0
blueocean-events:1.0.1
blueocean-git-pipeline:1.0.1
blueocean-github-pipeline:1.0.1
blueocean-i18n:1.0.1
blueocean-jwt:1.0.1
blueocean-personalization:1.0.1
blueocean-pipeline-api-impl:1.0.1
blueocean-pipeline-editor:0.2.0
blueocean-rest-impl:1.0.1
blueocean-rest:1.0.1
blueocean-web:1.0.1
blueocean:1.0.1
bouncycastle-api:2.16.1
branch-api:2.0.9
build-timeout:1.18
build-timestamp:1.0.1
buildrotator:1.2
cloudbees-folder:6.0.4
cobertura:1.10
conditional-buildstep:1.3.5
config-file-provider:2.16.0
credentials-binding:1.11
credentials:2.1.13
description-setter:1.11-SNAPSHOT (private-da0d0e96-sylvain)
display-url-api:2.0
docker-commons:1.6
docker-workflow:1.11
durable-task:1.13
ec2:1.37-SNAPSHOT (private-a0564f08-sylvain)
email-ext:2.57.2
envinject:2.1
external-monitor-job:1.7
favorite:2.3.0
flexible-publish:0.15.2
ghprb:1.37.0
git-client:2.4.6
git-server:1.7
git:3.3.0
github-api:1.85.1
github-branch-source:2.0.6
github-oauth:0.27
github-organization-folder:1.6
github-pullrequest:0.1.0-SNAPSHOT (private-f6d9e2fb-sylvain)
github:1.27.1-SNAPSHOT (private-42e89527-sylvain)
gradle:1.26
groovy:2.0
handlebars:1.1.1
http_request:1.8.19
icon-shim:2.0.3
jackson2-api:2.7.3
javadoc:1.4
jquery-detached:1.2.1
junit:1.20
ldap:1.15
mailer:1.20
managed-scripts:1.3
mapdb-api:1.0.9.0
matrix-auth:1.6
matrix-project:1.11
maven-plugin:2.15.1
metrics:3.1.2.10
momentjs:1.1.1
node-iterator-api:1.5.0
pam-auth:1.3
pipeline-build-step:2.5
pipeline-github-lib:1.0
pipeline-graph-analysis:1.4
pipeline-input-step:2.7
pipeline-milestone-step:1.3.1
pipeline-model-api:1.1.4
pipeline-model-declarative-agent:1.1.1
pipeline-model-definition:1.1.4
pipeline-model-extensions:1.1.4
pipeline-rest-api:2.8
pipeline-stage-step:2.2
pipeline-stage-tags-metadata:1.1.4
pipeline-stage-view:2.8
plain-credentials:1.4
pubsub-light:1.8
rebuild:1.25
resource-disposer:0.6
run-condition:1.0
scm-api:2.1.1
script-security:1.28
secondary-timestamper-plugin:1.1
simple-theme-plugin:0.3
sse-gateway:1.15
ssh-agent:1.15
ssh-credentials:1.13
ssh-slaves:1.17
structs:1.7
subversion:2.7.2
timestamper:1.8.8
token-macro:2.1
variant:1.1
windows-slaves:1.3.1
workflow-aggregator:2.5
workflow-api:2.17
workflow-basic-steps:2.5
workflow-cps-global-lib:2.8
workflow-cps:2.34
workflow-durable-task-step:2.11
workflow-job:2.11
workflow-multibranch:2.15
workflow-scm-step:2.4
workflow-step-api:2.11
workflow-support:2.14
ws-cleanup:0.33

EDIT: added some groovy functions EDIT2: sorted list of plugins

syl20bnr avatar Jun 12 '17 17:06 syl20bnr

Wow, ah, do you mean just multi-branch jobs or github-branchsource? I don't follow all this pipeline plugins but would like to make multibranch support of course. There is unreleased freestyle-multibranch-plugin that i can pick for reference implementation. If you need symbols, then let's add them in github-plugin and this plugin.

KostyaSha avatar Jul 06 '17 00:07 KostyaSha

I was using regular Pipeline job for this test. With the pipeline script above I observed that the job was executed twice but I don't recall on which event, I will have to re-do a test from scratch. I'll try to find some time to do it this week. Thank you for the help 👍

syl20bnr avatar Jul 06 '17 20:07 syl20bnr

FWIW I've noticed that when utilizing the GH org plugin, webhooks are created on both the Organization and Repository level. Thus triggering each push twice... Remove one of those and you should be good to go.

Geethree avatar Nov 01 '17 19:11 Geethree