Send status updates to hosted GitLab instances

This is something that is currently done for GitLab.com accounts, but not hosted GitLab CE instances.

Great idea, thanks for the #feature-request @alteris_dev! :slight_smile:

Hello! I’m wondering if there are any plans to implement commit status integration for hosted GitLab? We use a hosted GitLab CE instance and we’d love to have this feature. It doesn’t have to be fancy, just a field to put the instance URL and the personal access token.

2 Likes

Definitely planned @philippe_fcg - to bump its priority please vote on this #feature-request! :wink:

Is there a timeline for this feature? We need it as soon as possible …

1 Like

No ETA yet, sorry, but keep the votes coming to bump the priority :wink:

Since BuddyBuild is shutting down for Android users, and all other parties don’t work with Gitlab this feature could set you apart from the competition

2 Likes

Got it, thanks for the bump @bartjo!

Note: self hosted GitLab should work in general on bitrise.io except the build status sending, which is only available for gitlab.com

Would there be a way to manually do it using steps in the workflow ?

2 Likes

Does your recent introduction of outgoing webhooks (http://devcenter.bitrise.io/api/outgoing-webhooks/) solve this issue?

Thanks,

Sure, it’s definitely possible. The only thing you can’t report via a step is if the build is aborted before the step would run.

We don’t have a step for this yet. I added it to our list, but if anyone would have the time to get started on it we’re always happy to help! Related docs: http://devcenter.bitrise.io/bitrise-cli/create-your-own-step/

You can also find an example step which does exactly this, reports the build status, just for GitHub (both hosted and self-hosted) instead of for GitLab: GitHub - bitrise-steplib/steps-github-status

Not directly. The outgoing webhook sends data in its own format, you have to convert that with your own server/service to GitLab specific format otherwise GitLab won’t accept it.

Update / note: you can find the related docs at https://docs.gitlab.com/ce/api/commits.html#post-the-build-status-to-a-commit

There’s even a curl example there - you can drop that into a Script step.

curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"

We’ll try to work on a related Step ASAP but can’t promise any ETA right now.

Hey guys,

Thanks for the official build status.

Thanks for making Bitrise awesome!

1 Like

Glad to hear you like it @ClementAppsolute ! :wink:

Are you going to implement this for GitLab instances specifically? Would be awesome to have this for e.g. BitBucket Server as well :slight_smile:
Or would this require an additional feature request?

Thank you @viktorbenei for the curl example. I’ve further investigated the possibilities and this is our working script step at the moment:

    - script:
        title: Report Build Status to GitLab
        inputs:
        - content: |-
            #!/usr/bin/env bash
            if [ $BITRISE_BUILD_STATUS == "0" ]; then
              GITLAB_BUILD_STATE="success"
            else
              GITLAB_BUILD_STATE="failed"
            fi

            curl --request POST --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_KEY" "https://$GITLAB_CUSTOM_DOMAIN/api/v4/projects/$GITLAB_PROJECT_ID/statuses/$GIT_CLONE_COMMIT_HASH?state=$GITLAB_BUILD_STATE&target_url=$BITRISE_BUILD_URL&name=Bitrise-CI"
        is_always_run: true

You can just copy and paste the step to your bitrise.yml file and add the following ENV variables:

GITLAB_CUSTOM_DOMAIN
The domain of your hosted GitLab instance – without https:// – e.g. gitlab.example.com.

GITLAB_PRIVATE_KEY
A personal access token with API checkmark checked – the account must have access to the project – see here on how to get such a token. Looks something like this: 9koXpg98eAheJpvBs5tK .

GITLAB_PROJECT_ID
The project ID which you can find by going into your projects “Settings” > “General” page and expand the “General project settings”. Here’s a screenshot:

The bad news is that this script step can only report success and failed state to GitLab. pending or running states would be great as well, but I don’t know if this is even possible with this method.

Still, better than nothing, right? :tada:

Additionally, you may want to set the following option in your project settings:

Then your merge requests will look something like this when Bitrise CI fails (note the disabled Merge button):

Please note that we came across an issue with the above solution – once the example Merge Request passed on Bitrise CI, the Merge Request still was not mergable. This might be an issue with GitLab, maybe. In any case, this is what it looks like now:

When we look at the Merge Request from the list of Merge Requests you can see though, that the successful state was correctly reported to GitLab:

Therefore we had to uncheck the Only allow merge requests to be merged if the pipeline succeeds option for now. I linked this thread on the related GitLab issue page here.

Thanks for all the info & screenshots @jamitlabs, we really appreciate it!!

Quick question, did you try to use our GitLab status step (https://github.com/bitrise-steplib/steps-gitlab-status)?