Build status for Bitbucket Server

Adding built in support for this was mentioned in Send status updates to hosted GitLab instances - #16 by MartinStraub

@MartinStraub when we get to work on the built in support (meaning to do it without any Build Step) we’ll definitely support the self-hosted versions of the “big three” (GitHub, Bitbucket, GitLab).
Might take a bit more time for Bitbucket as the self hosted version of Bitbucket (Bitbucket Server) is quite a bit different compared to bitbucket.org, in fact it wasn’t even called Bitbucket initially, it was Atlassian Stash (Git - Atlassian Blog), and even to this day these have separate API, webhook etc. formats, while GitHub and GitLab self-hosted have the same API & other formats as the .com hosted versions. In any case, a step for Bitbucket Server is definitely possible, similar to the existing GitHub Status (GitHub - bitrise-steplib/steps-github-status) and GitLab Status (GitHub - bitrise-steplib/steps-gitlab-status) steps. You can create a step if you have some time, it’s quite simple - a related recent blog post: How to create and share your own Bitrise step - Bitrise

I just wanted to create a new feature request for this so it’s tracked. Are there any updates on this?

No updates yet unfortunately, thanks for creating this #feature-request, we’ll update you here about the progress!

In the meantime the workaround is to use a Script step and call the related Bitbucket Server endpoint from that with e.g. curl.

Thanks for the update.

Yeah, custom scripts are what we’re using now.

A script at the beginning to report progress:

- script@1.1.5:
        inputs:
        - content: |-
            #!/usr/bin/env bash

            curl https://$STASH_DOMAIN/rest/build-status/1.0/commits/$GIT_CLONE_COMMIT_HASH \
              -u $STASH_USER:$STASH_PASSWORD \
              -H 'Content-Type: application/json' \
              --data-binary \
              $'{
                "state": "INPROGRESS",
                "key": "Bitrise",
                "name": "Bitrise '$APP' #'$BITRISE_BUILD_NUMBER'",
                "url": "'$BITRISE_BUILD_URL'",
                "description": "'$BITRISE_TRIGGERED_WORKFLOW_ID' workflow"
               }' \
               --compressed
        title: Report build progress

And one at the end to report success or fail:

- script@1.1.5:
        is_always_run: true
        inputs:
        - content: |-
            #!/usr/bin/env bash

            if [ $BITRISE_BUILD_STATUS == "0" ]; then
              BUILD_STATE="SUCCESSFUL"
            else
              BUILD_STATE="FAILED"
            fi

            curl https://$STASH_DOMAIN/rest/build-status/1.0/commits/$GIT_CLONE_COMMIT_HASH \
              -u $STASH_USER:$STASH_PASSWORD \
              -H 'Content-Type: application/json' \
              --data-binary \
              $'{
                "state": "'$BUILD_STATE'",
                "key": "Bitrise",
                "name": "Bitrise '$APP' #'$BITRISE_BUILD_NUMBER'",
                "url": "'$BITRISE_BUILD_URL'",
                "description": "'$BITRISE_TRIGGERED_WORKFLOW_ID' workflow"
               }' \
               --compressed

It does mean we need STASH_USER and STASH_PASSWORD secrets

3 Likes

Thanks for the scripts @yonas, I’m sure it’ll help others in the future, until we roll out the built in support for Bitbucket Server status reporting! :slight_smile:

Thanks for the script @yonas ! I’ve adjusted it a bit and created a bitrise step from it! See https://github.com/teameh/bitrise-step-bitbucket-server-post-build-status/blob/master/step.sh

It works great, but when running it after my Fastlane step it will always be successful instead of failed when fastlane exists with an error. Any tips @viktorbenei?

Hi @teameh! Could you please shoot us a build URL where you’re getting a false pass so we can have a think on this? Thanks!

thx @teameh for the step. I’m facing the same issue. It will start out with FAILED status instead of IN PROGRESS status at the beginning. Any update how to fix this?