Skip to content

Instantly share code, notes, and snippets.

@shenxianpeng
Last active July 25, 2021 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shenxianpeng/bd5eddc5fb39e54110afb8e2e7a6c4fb to your computer and use it in GitHub Desktop.
Save shenxianpeng/bd5eddc5fb39e54110afb8e2e7a6c4fb to your computer and use it in GitHub Desktop.
Update Bitbucket build status with REST API
#!/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
@shenxianpeng
Copy link
Author

Test result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment