Skip to content

GitLab CI/CD

Add one job to .gitlab-ci.yml and a failed pipeline arrives on your devices with a button that opens it in GitLab.

This uses an API Source, with curl and jq.

  1. In the Pocketbell app, create a Source named GitLab, choose API, and copy its key.

  2. In the project, open Settings → CI/CD → Variables, click Add variable, set the key to POCKETBELL_KEY and the value to your key, and set Visibility to Masked. Leave Protect variable off, or only protected branches can use it.

  3. Add this job to .gitlab-ci.yml:

    notify-failure:
    stage: .post
    image: alpine:3
    when: on_failure
    script:
    - apk add --no-cache curl jq
    - |
    jq -n --arg title "Pipeline failed: $CI_PROJECT_NAME" \
    --arg message "$CI_COMMIT_REF_NAME: $CI_COMMIT_TITLE" \
    --arg url "$CI_PIPELINE_URL" \
    '{title: $title, message: $message, priority: "important", tags: ["gitlab"],
    url: $url, url_title: "Open pipeline"}' |
    curl --fail-with-body -sS https://api.pocketbell.dev/v1/messages \
    -H "Authorization: Bearer $POCKETBELL_KEY" \
    -H "Content-Type: application/json" \
    --data @-
  • .post is the stage GitLab runs last, and when: on_failure runs the job only when something before it failed.
  • jq --arg turns each value into a JSON string, so a commit title with quotes in it still makes a valid request.
  • For a notification when a deploy finishes, add a second job with when: on_success and priority: "normal".

The job’s log shows Pocketbell’s answer:

  • 401 invalid_api_key: the variable is missing, or it’s protected and this branch isn’t.
  • 400 invalid_request: details in the answer names the field.