Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run the command on a git clone (using current branch)
#!/bin/bash
# Clones your existing repo and run the subsequent command off this clone
# Tests are run on the the current branch at the time of cloning
#
# Note that you can work on the next bug while this is going on as
# tests are run off a cloned repo.
#
# $ remote.sh mvn clean install
# runs 'mvn clean install'
#
# A notification is sent upon build completion if your OS supports it:
# - on Mac OS, install Growl and grownnotifier
# - on Linux, install send-notify
#
# Many thanks to David Gageot (http://blog.javabien.net) for the inspiration and optimization of this script.
#
# Released under the WTFPL license version 2 http://sam.zoy.org/wtfpl/
#
# Copyright (c) 2010 David Gageot
# Copyright (c) 2010-2011 Emmanuel Bernard
# Copyright (c) 2011 Sanne Grinovero
#the cloned repo will live in ../DIRECTORY_ROOT/REPO_DIRECTORY
DIRECTORY_ROOT="../privatebuild/"
#get the lastest part of the directory name
IFS="/"
SPLIT_DIR=(`pwd`)
SIZE=${#SPLIT_DIR[@]}
let LAST_INDEX=$SIZE-1
DIRECTORY_SUFFIX=${SPLIT_DIR[$LAST_INDEX]}
IFS=""
DIRECTORY="${DIRECTORY_ROOT}${DIRECTORY_SUFFIX}"
BRANCH=`git branch | grep "*" | awk '{print $NF}'`
#fresh clone
rm -Rf $DIRECTORY
git clone -slb "$BRANCH" . $DIRECTORY
cd $DIRECTORY
echo ""
echo "***** Working on branch $BRANCH *****"
echo ""
say() {
if [ `uname -s` == "Darwin" ]; then
# On Mac OS, notify via Growl
which -s growlnotify && growlnotify --name Remote --sticky --message "'$CMD_DISPLAY' on branch $BRANCH - $RESULT"
fi
if [ `uname -s` == "Linux" ]; then
# On Linux, notify via notify-send
which notify-send && notify-send "'$CMD_DISPLAY' on branch $BRANCH" "$RESULT"
fi
}
if [[ $# -eq 0 ]]; then
echo "Usage remote.sh <command to run>"
else
CMD_DISPLAY="$@"
fi
$@
if [ $? -eq 0 ]; then
RESULT="SUCCESS"
echo $RESULT
say
else
RESULT="FAILURE"
echo $RESULT
say
exit $?
fi
@hferentschik

This comment has been minimized.

Copy link

@hferentschik hferentschik commented Dec 6, 2011

For the record, I do the same thing with Jenkins. I have a whole bunch of jobs configured, but also one which build my current branch.
Two things are important there

  • The right repo url. I use

     file:///<your-path-to-the-local-git-checkout>
    
  • A way to switch the git clone to the right branch (the one which is active in your checkout). I do this via a Shell Command build step

    git checkout `(cd ~/work/hibernate/git/validator/; git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)`
    

With this setup I can also build my current branch on the press on the button while I still can continue working. On top of this I get a build history, logs, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment