-
-
Save michalskalski/5ee32c66e2c701e487fbca42d21c4967 to your computer and use it in GitHub Desktop.
workaround for JENKINS-28447 in case of github trigger plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reconfigure job to have Pipeline DSL configured inside job, instead of from scm. | |
// Put snippet below to pipeline text box | |
// Define additional job parameters: | |
// GITHUB_PROJECT: string, URL to your GitHub repository | |
// GITHUB_AUTH: string, credentials ID to use in case of private GitHub repository | |
node { | |
dir('pipeline_handover') { | |
checkout([$class: 'GitSCM', | |
branches: [[name: "origin-pull/$GITHUB_PR_NUMBER/$GITHUB_PR_COND_REF"]], | |
doGenerateSubmoduleConfigurations: false, | |
extensions: [], | |
submoduleCfg: [], | |
userRemoteConfigs: [ | |
[credentialsId: "${GITHUB_AUTH}", | |
name: 'origin-pull', | |
refspec: "+refs/pull/$GITHUB_PR_NUMBER/*:refs/remotes/origin-pull/$GITHUB_PR_NUMBER/*", | |
url: "${GITHUB_PROJECT}"]]]) | |
} | |
load 'pipeline_handover/Jenkinsfile' | |
} | |
// This part of example goes to Jenkins file inside your Git tree: | |
// Code below would checkout Git content in both scenarios for triggering builds | |
// (pull requests, push to branch) and share same Jenkinsfile | |
node('docker') { | |
stage 'Checkout own content' | |
dir(current_project) { | |
if (binding.variables.get("GITHUB_PR_NUMBER")) { | |
// we are building pull request | |
checkout([$class: 'GitSCM', | |
branches: [[name: "origin-pull/$GITHUB_PR_NUMBER/$GITHUB_PR_COND_REF"]], | |
userRemoteConfigs: [ | |
[credentialsId: "${GITHUB_AUTH}", | |
name: 'origin-pull', | |
refspec: "+refs/pull/$GITHUB_PR_NUMBER/*:refs/remotes/origin-pull/$GITHUB_PR_NUMBER/*", | |
url: "${GITHUB_PROJECT}"]]]) | |
} else { | |
checkout scm | |
} | |
} | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment