Last active
July 25, 2021 12:20
-
-
Save shenxianpeng/bd5eddc5fb39e54110afb8e2e7a6c4fb to your computer and use it in GitHub Desktop.
Update Bitbucket build status with REST API
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
#!/bin/sh | |
username=your-bitbucket-user | |
password=your-bitbucket-password | |
commit_id='58577d7d4892bc4ef2c4375028c19b27921e2485' | |
# build_result has 3 status: SUCCESSFUL, FAILED, INPROGRESS | |
build_result='SUCCESSFUL' | |
description='Manully update bitbucket status' | |
build_name='test #1' | |
build_url=http://localhost:8080/job/test/ | |
bitbucket_rest_api='https://myorg.bitbucket.com/rest/build-status/latest/commits' | |
gen_post_data() | |
{ | |
cat <<EOF | |
{ | |
"state": "$build_result", | |
"key": "$commit_id", | |
"name": "$build_name", | |
"url": "$build_url", | |
"description": "$description" | |
} | |
EOF | |
} | |
echo "$(gen_post_data)" | |
curl -u $username:$password \ | |
-H "Accept: application/json" \ | |
-H "Content-Type:application/json" \ | |
-X POST $bitbucket_rest_api/$commit_id --data "$(gen_post_data)" | |
if [ $? -ne 0 ] | |
then | |
echo "$0: Update bitbucket build status failed." | |
exit 1 | |
else | |
echo "$0: Update bitbucket build status success." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test result: