Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions general/bitbucket-commit-status/appcenter-post-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
#
# Report build status next to Bitbucket commit.
#
# Adjust settings in bitbucket.sh file
#
# Contributed by: Sohayb Hassoun

source bitbucket.sh

case $AGENT_JOBSTATUS in
Failed)
bitbucket_set_status_fail
;;
Canceled)
bitbucket_set_status_stopped
;;
*)
bitbucket_set_status_success
;;
esac
11 changes: 11 additions & 0 deletions general/bitbucket-commit-status/appcenter-post-clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# Report build status next to Bitbucket commit.
#
# Adjust settings in bitbucket.sh file
#
# Contributed by: Sohayb Hassoun

source bitbucket.sh

bitbucket_set_status_in_progress
50 changes: 50 additions & 0 deletions general/bitbucket-commit-status/bitbucket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Report build status next to Bitbucket commit.
#
# - Fill in BITBUCKET_USER that owns the repo
# - Fill MS_APPCENTER_ORG is the AppCenter organization that owns the app
# - Fill MS_APPCENTER_APP is AppCenter's app name
# - BITBUCKET_TOKEN is your user and Base64 encoding of "user:password", this should be an environment variable defined in AppCenter's Job's configurations
#
# Contributed by: Sohayb Hassoun

cd $APPCENTER_SOURCE_DIRECTORY

BITBUCKET_USER=""
MS_APPCENTER_ORG=""
MS_APPCENTER_APP=""

bitbucket_set_status() {
local status job_status
local "${@}"

build_url="https://appcenter.ms/orgs/$MS_APPCENTER_ORG/apps/$MS_APPCENTER_APP/build/branches/$APPCENTER_BRANCH/builds/$APPCENTER_BUILD_ID"

curl -X POST https://api.bitbucket.org/2.0/repositories/$BITBUCKET_USER/$BUILD_REPOSITORY_NAME/commit/$BUILD_SOURCEVERSION/statuses/build -d \
"{
\"state\": \"$status\",
\"key\": \"$APPCENTER_BUILD_ID\",
\"name\": \"$APPCENTER_BRANCH\",
\"url\": \"$build_url\",
\"description\": \"The build status is: $job_status!\"
}" \
-H "Authorization: Basic $BITBUCKET_TOKEN" \
-H "Content-Type: application/json"
}

bitbucket_set_status_success() {
bitbucket_set_status status="SUCCESSFUL" job_status="$AGENT_JOBSTATUS"
}

bitbucket_set_status_fail() {
bitbucket_set_status status="FAILED" job_status="$AGENT_JOBSTATUS"
}

bitbucket_set_status_stopped() {
bitbucket_set_status status="STOPPED" job_status="$AGENT_JOBSTATUS"
}

bitbucket_set_status_in_progress() {
bitbucket_set_status status="INPROGRESS" job_status="In progress"
}