Skip to content

Instantly share code, notes, and snippets.

View omehegan's full-sized avatar

Owen Mehegan omehegan

  • CloudBees
  • Melbourne, Australia
View GitHub Profile
@omehegan
omehegan / gist:453a34d0dbd6e8099eef9d3398352593
Created April 26, 2017 21:48
Warn on unpushed git changes
export PS1="\u@\H \w \$(parse_git_branch)\$ "
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
ref=${ref#refs/heads/}
unpushed=$(git log origin/$ref..$ref 2> /dev/null) || return
if [ "$unpushed" ]; then
warn=' - UNPUSHED!'
fi
echo "("$ref$warn")"
@omehegan
omehegan / gist:7ecc04f966a4c0226ff1b0198456e452
Last active August 16, 2017 22:36
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