Deployment Change Tracking

GitLab CI + Alert24: Deployment Change Tracking

Record GitLab CI deployments in Alert24's change log using after_script or a dedicated notify job. Includes variable mapping and multi-environment support.

GitLab CI's after_script runs after every job regardless of success or failure, making it a reliable hook for logging deployment changes to Alert24.

Before you start

You'll need:

  • An Alert24 API key with write scope, stored as a GitLab CI/CD variable (ALERT24_API_KEY under Settings → CI/CD → Variables, masked)
  • GitLab CI pipeline that deploys your application

Add to your .gitlab-ci.yml

deploy:production:
  stage: deploy
  environment:
    name: production
  script:
    - ./scripts/deploy.sh  # your existing deploy command
  after_script:
    - |
      if [ "$CI_JOB_STATUS" = "success" ]; then
        curl -s -X POST https://app.alert24.net/api/v1/changes \
          -H "Authorization: Bearer $ALERT24_API_KEY" \
          -H "Content-Type: application/json" \
          -d "{
            \"summary\": \"Deployed $CI_PROJECT_NAME @ $CI_COMMIT_SHORT_SHA\",
            \"change_type\": \"deployment\",
            \"environment\": \"production\",
            \"branch\": \"$CI_COMMIT_BRANCH\",
            \"commit_sha\": \"$CI_COMMIT_SHA\",
            \"commit_message\": $(echo \"$CI_COMMIT_MESSAGE\" | jq -Rs .),
            \"pipeline_url\": \"$CI_PIPELINE_URL\",
            \"changed_by\": \"$GITLAB_USER_LOGIN\",
            \"source\": \"gitlab-ci\",
            \"tags\": [\"gitlab\", \"$CI_ENVIRONMENT_NAME\"]
          }"
      fi

Alternative: dedicated notify job

For cleaner pipeline structure, add a separate job that depends on the deploy job:

notify:alert24:
  stage: .post
  needs: [deploy:production]
  script:
    - |
      curl -s -X POST https://app.alert24.net/api/v1/changes \
        -H "Authorization: Bearer $ALERT24_API_KEY" \
        -H "Content-Type: application/json" \
        -d "{
          \"summary\": \"Deployed $CI_PROJECT_NAME @ $CI_COMMIT_SHORT_SHA\",
          \"change_type\": \"deployment\",
          \"environment\": \"$CI_ENVIRONMENT_NAME\",
          \"branch\": \"$CI_COMMIT_BRANCH\",
          \"commit_sha\": \"$CI_COMMIT_SHA\",
          \"pipeline_url\": \"$CI_PIPELINE_URL\",
          \"pr_url\": \"$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID\",
          \"pr_number\": $CI_MERGE_REQUEST_IID,
          \"changed_by\": \"$GITLAB_USER_LOGIN\",
          \"source\": \"gitlab-ci\"
        }"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Key GitLab CI variables

GitLab variable Alert24 field
$CI_COMMIT_SHA commit_sha
$CI_COMMIT_SHORT_SHA Part of summary
$CI_COMMIT_MESSAGE commit_message
$CI_COMMIT_BRANCH branch
$CI_PIPELINE_URL pipeline_url
$CI_ENVIRONMENT_NAME environment
$GITLAB_USER_LOGIN changed_by
$CI_MERGE_REQUEST_IID pr_number

Tips

  • $CI_JOB_STATUS: In after_script, this variable reflects whether the main script block succeeded. Use it to skip logging on failed deploys.
  • Multiple services: If your pipeline deploys multiple microservices, add the Alert24 step per deploy job with the appropriate service_id for each.
  • Protected variables: Mark ALERT24_API_KEY as a protected variable so it's only available on protected branches (main, production).