Skip to content

Instantly share code, notes, and snippets.

@szabacsik
Last active August 13, 2018 16:11
Show Gist options
  • Save szabacsik/71b7439491a44fd965b5c2872293b341 to your computer and use it in GitHub Desktop.
Save szabacsik/71b7439491a44fd965b5c2872293b341 to your computer and use it in GitHub Desktop.
Simple build configurations to notify an api endpoint when a new commit pushed
image: php:7.2.7
pipelines:
default:
- step:
script:
- apt-get update && apt-get install -y --no-install-recommends jq
- export TOKEN=...
- export API=https://.../
- export TZ="Europe/Budapest"
- export TIME=$(date +'%Y.%m.%d. %H:%M:%S.%3N %Z')
- "curl $API -o response.json --insecure -X POST -H 'Content-Type: application/json' -d '{\"slug\":\"'\"$BITBUCKET_REPO_SLUG\"'\",\"uuid\":\"'\"$BITBUCKET_REPO_UUID\"'\",\"build\":\"'\"$BITBUCKET_BUILD_NUMBER\"'\",\"repository\":\"'\"$BITBUCKET_REPO_SLUG\"'\",\"branch\":\"'\"$BITBUCKET_BRANCH\"'\",\"commit\":\"'\"$BITBUCKET_COMMIT\"'\",\"token\":\"'\"$TOKEN\"'\",\"when\":\"'\"$TIME\"'\"}'"
- jq '.' response.json
- export error=$(jq '.["error"]' response.json 2> /dev/null)
- if [ "$error" != "true" ] && [ "$error" != "false" ] && [ "$error" != '"false"' ] && [ "$error" != '"true"' ]; then echo "Invalid response"; exit 1; fi
- if [ "$error" == "false" ] || [ "$error" == '"false"' ]; then export success=true; else export success=false; fi
- if [ $success == "true" ]; then echo "Successful data transfer"; exit 0; else echo "Data transfer failed"; exit 1; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment