How to build a botboard to build a git poll?

How can a small cron, bash + make, based on a script (for example, much smaller and less reliable than, for example, Hudson), build a bot-poll a git repo and determine whether it will build now - for example. if during periodic pulling from a remote git repository he got a new code?

Currently it looks like this:

git fetch  > build_log.txt 2>&1
if [ $? -eq 0 ]
then
  echo "Fetch from git done";
  git merge FETCH_HEAD >> build_log.txt 2>&1 ;
  if [ $? -eq 0 ]
  then
    echo "Merge via git done"; ...
    # builds unconditionally at the moment
  fi
fi
+5
source share
3 answers

If nothing was selected, then "get fetch" will not print any lines, so just check the file size zero in the build_log.txt file:

git fetch > build_log.txt 2>&1
if [ -s build_log.txt ]
then
   # build
fi
+2
source

, , , .

git rev-parse <branch_name>

sha1 . :

  • sha1

. , , - , , git fetch ( , git fetch ).

script, ( , ):

if [ ! -f prev_head ]; # initialize if this is the 1st poll
then
  git rev-parse master > prev_head
fi
# fetch & merge, then inspect head
git fetch  > build_log.txt 2>&1
if [ $? -eq 0 ]
then
  echo "Fetch from git done";
  git merge FETCH_HEAD >> build_log.txt 2>&1 ;
  git rev-parse master > latest_head
  if ! diff latest_head prev_head > /dev/null ;
  then
    echo "Merge via git done"; ...
    cat latest_head > prev_head # update stored HEAD
    # there has been a change, build
  fi
fi
+15

If you have control over a remote repo, you might consider doing this with hooks instead of polling. This way, your script is only called when there is something new to build.

+4
source

All Articles