0

Based on Automating with Cloud Hooks I've implemented Slack notification based on Simple Slack Notification Bash Script

site="$1"
target_env="$2"
source_branch="$3"
deployed_tag="$4"
repo_url="$5"
repo_type="$6"

FILE=$HOME/slack_settings

if [ -f $FILE ]; then
  # Load the Slack webhook URL (which is not stored in this repo).
  . $HOME/slack_settings

  # Post deployment notice to Slack

  if [ "$source_branch" != "$deployed_tag" ]; then
    curl -X POST --data-urlencode "payload={\"username\": \"Acquia Cloud\", \"text\": \"An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.\", \"icon_emoji\": \":acquiacloud:\"}" $SLACK_WEBHOOK_URL
  else
    curl -X POST --data-urlencode "payload={\"username\": \"Acquia Cloud\", \"text\": \"An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.\", \"icon_emoji\": \":acquiacloud:\"}" $SLACK_WEBHOOK_URL
  fi
else
  echo "File $FILE does not exist."
fi

It works correctly, it sends the message,

An updated deployment has been made to mysitexxxx.dev using tag dev.

But What I need is the commit's message,How can I get commit message on Acquia post-code-update?

1

The commit message isn't passed in to the script, so you have to get it from somewhere else. I'm not sure if there is a git repository available to the cloud hook scripts on Acquia's cloud servers in general (it seems like there must be, but...I can't find an answer about where it is in their docs). You do have the repository url and the branch/tag, so you could try a shallow clone of the tag to get the data:

git clone --depth 1 --branch $deployed_tag $repo_url clonedirectory cd clonedirectory commit_message=`git show -s --format=%B` ... echo $commit_message

You can use the $commit_message variable in the slack commands.

Of course...you have to figure out how to authenticate to the git repo and I'm not sure what's a great solution there.

Really I hope someone will reply with the location of a git clone that's available on cloud servers.

  • 1
    good tricky solution: I just use commit_message=git log -1 instead of commit_message=git show -s --format=%B – Yusef Jan 16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.