Last active
February 21, 2021 07:14
-
-
Save antrew/965e0262e329146c102694b5829041a5 to your computer and use it in GitHub Desktop.
This file contains 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
#!groovy | |
def handleCheckout = { | |
if (env.gitlabMergeRequestId) { | |
sh "echo 'Merge request detected. Merging...'" | |
def credentialsId = scm.userRemoteConfigs[0].credentialsId | |
checkout ([ | |
$class: 'GitSCM', | |
branches: [[name: "${env.gitlabSourceNamespace}/${env.gitlabSourceBranch}"]], | |
extensions: [ | |
[$class: 'PruneStaleBranch'], | |
[$class: 'CleanCheckout'], | |
[ | |
$class: 'PreBuildMerge', | |
options: [ | |
fastForwardMode: 'NO_FF', | |
mergeRemote: env.gitlabTargetNamespace, | |
mergeTarget: env.gitlabTargetBranch | |
] | |
] | |
], | |
userRemoteConfigs: [ | |
[ | |
credentialsId: credentialsId, | |
name: env.gitlabTargetNamespace, | |
url: env.gitlabTargetRepoSshURL | |
], | |
[ | |
credentialsId: credentialsId, | |
name: env.gitlabSourceNamespace, | |
url: env.gitlabSourceRepoSshURL | |
] | |
] | |
]) | |
} else { | |
sh "echo 'No merge request detected. Checking out current branch'" | |
checkout ([ | |
$class: 'GitSCM', | |
branches: scm.branches, | |
extensions: [ | |
[$class: 'PruneStaleBranch'], | |
[$class: 'CleanCheckout'] | |
], | |
userRemoteConfigs: scm.userRemoteConfigs | |
]) | |
} | |
} | |
node() { | |
stage('setup') { | |
sh "env | sort" | |
handleCheckout() | |
sh "git branch -vv" | |
} | |
stage('test') { | |
sh "echo 'Throw in some tests here'" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment