Receive Notification from Acquia Cloud after code deploy or code update to Webex Spaces

If we using Acquia Cloud for Drupal Project Deployment, and we are using Webex in our project, use the below procedure to send notifications after successful code deployment.

Step 1 With your Webex email you need to log in to http://apphub.webex.com/

If we connect to that, you will see the steps for getting Webhook URL, Adding a name and Selecting a space, it will list all the Spaces available for your email. If you want, you can create your own specific Webex space, once it is done select that space and click on ADD, it will show the WEBHOOK URL, which we need to use in Acquia Cloud hooks.

In Acquia Project, we need to setup hooks Ref: For setup check https://docs.acquia.com/cloud-platform/develop/api/cloud-hooks/

Once we set up we should have the "hooks" folder we should see the below folder structure

In the above screenshot, we have two hooks

"post-code-deploy" -> The post-code-deploy hook is run whenever you use the Workflow page to deploy new code to an environment, either via drag-drop or by selecting an existing branch or tag from the Code drop-down list

"post-code-update" -> The post-code-update when an update/new changes happen to the branch or tag

In that folder we can add a shell script (filename.sh), we can create a file with any name, I used "Webex", as I am sending notifications to Webex

My filename.sh contain below code

When code deployment happens in Acquia we see our filename.sh script will run

/mnt/users/project_name/qa.shell /var/www/html/project_name.env/hooks/common/post-code-update/webex.sh site_name env branch_or_tag_name branch_or_tag_name acquia_project_url.git git < /dev/null

/mnt/users/project_name/qa.shell /var/www/html/project_name.env/hooks/common/post-code-deploy/webex.sh site_name env branch_or_tag_name branch_or_tag_name acquia_project_url.git git  < /dev/null

For the shell script site_name, env,source_branch, deployed_tag, repo_url, repo_type all are passed as variables

site="$1"
target_env="$2"
source_branch="$3"
deployed_tag="$4"
repo_url="$5"
repo_type="$6"
WEBEX_WEBHOOK_URL=$(php -r 'print_r(getenv("WEBEX_WEBHOOK_URL"));')


# Post deployment notice to Webex
if [ "$source_branch" != "$deployed_tag" ]; then
  curl -X POST -H "Content-Type: application/json" -d "{\"markdown\": \"An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.\"}" $WEBEX_WEBHOOK_URL
else
  curl -X POST -H "Content-Type: application/json" -d "{\"markdown\": \"An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.\"}" $WEBEX_WEBHOOK_URL
fi

In the Acquia Environment Variables, we need to create a custom Variable where we provide the WEBHOOK Url created above, once we add, we will be used in our shell script

Once the shell script is executed, we receive notifications to our Webex space.