Skip to content

Instantly share code, notes, and snippets.

@omehegan
Last active August 16, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omehegan/7ecc04f966a4c0226ff1b0198456e452 to your computer and use it in GitHub Desktop.
Save omehegan/7ecc04f966a4c0226ff1b0198456e452 to your computer and use it in GitHub Desktop.
Parse gitlab merge request ID from git commit message in Jenkins pipeline
def getMergeRequestId() {
sh "git show -s --format='%B' > commitmsg"
msg = readFile 'commitmsg'; msg = msg.trim()
def mr_id_match = msg =~ /!(\d+)/
if ( mr_id_match ) {
mr_id = mr_id_match[0][1]
echo "Found merge request ID $mr_id"
} else { mr_id = null }
mr_id_match = null // have to null this or we'll get NotSerializable errors from Jenkins
env.mergeRequestId = mr_id // set this so it can be used in the shell
return mr_id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment