Skip to content

Instantly share code, notes, and snippets.

@marsyang1
Created October 21, 2015 09:15
Show Gist options
  • Save marsyang1/7a68f97e0a0684630e84 to your computer and use it in GitHub Desktop.
Save marsyang1/7a68f97e0a0684630e84 to your computer and use it in GitHub Desktop.
Hg auto merge by Jenkins execute shell
# automerge.sh
USERNAME=${CREDENTIALS%:*}
PASSWORD=${CREDENTIALS#*:}
# proof of concept - don't echo this in real life :)
echo USERNAME=$USERNAME
echo USERNAME=$PASSWORD
# Jenkins uses "-e" parameter, but we want to handle the exit-code manually
set +e
WORKING_DIR=$PWD
# show current reversion
hg id -i
# reset local changes
hg update -C .
# get changes from repository
# hg pull
# update to branch
hg update -C trial
# show trail reversion
hg id -i
# try the merge
hg merge SAT --config "ui.merge=internal:merge"
mergereturn=$?
case $mergereturn in
0)
echo '##################################'
echo '##### Merge successfully #####'
echo '##################################'
# commit and push
hg commit -m 'Automerge from jenkins' -u 'jenkins'
hg push http://$USERNAME:[email protected]:8000/scm/hg/anno-pom
rc=0
;;
1)
echo '####################################################'
echo '##### Merge-Conflict, manual merge needed! #####'
echo '####################################################'
rc=1
;;
255)
echo '############################################'
echo '##### No Changes (Return-Code 255) #####'
echo '############################################'
hg push http://$USERNAME:[email protected]:8000/scm/hg/anno-pom
rc=0
;;
*)
echo '###############################################'
echo "##### Merge-Returncode : $mergereturn #####"
echo '###############################################'
rc=1
;;
esac
# reset local changes
hg update -C .
exit $rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment