当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Combine two post-receive hooks

问题描述:

How can I combine two post-receive hooks? The first one is a git-slack integration and runs with the following loop:

while read line

do

set -- $line

notify $*

RET=$?

done

and the second one is for my deployment and looks like this:

while read oldrev newrev refname line

do

branch=$(git rev-parse --symbolic --abbrev-ref $refname)

if [ "master" = "$branch" ]; then

# some deployment commands

elif [ "development" = "$branch" ]; then

# some other deployment commands

fi

done

No matter what branch I use for git, I would like to be able to send notifications to slack.

Any tips on how to combine both loops?

网友答案:

This has not been tested but should work:

while read oldrev newrev refname line
do
  set -- "$oldrev $newrev $refname $line"
  notify $*

  # Not sure the return value is needed since it isn't being used anywhere
  RET=$?

  branch=$(git rev-parse --symbolic --abbrev-ref $refname)
  if [ "master" = "$branch" ]; then
    # some deployment commands
  elif [ "development" = "$branch" ]; then
   # some other deployment commands
  fi
done

Hope this helps

分享给朋友:
您可能感兴趣的文章:
随机阅读: