Last active
August 13, 2018 16:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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