Create deployments from GitLab Pipelines

Notifying elmah.io of new deployments on GitLab Pipelines can be done by adding a bit of YAML code. You can create the integration in whatever job you prefer. In the following example, a deploy job is extended to create a new deployment on elmah.io:

deploy-job:
  stage: deploy
  environment: production
  variables:
    API_KEY: 'API_KEY'
    LOG_ID: 'LOG_ID'
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."
    - |
      curl --location --request POST "https://api.elmah.io//v3/deployments?api_key=$API_KEY" --header 'Content-Type: application/x-www-form-urlencoded' --data "version=$CI_PIPELINE_ID&description=$CI_COMMIT_MESSAGE&userName=$GITLAB_USER_NAME&userEmail=$GITLAB_USER_EMAIL&logId=$LOG_ID"

The code defines two new variables named API_KEY and LOG_ID. Replace the values with an API key (Where is my API key?) with permission to create deployments and the ID (Where is my log ID?) of the log to create the deployment in.

The script uses curl to call the elmah.io API. As part of the HTTP POST, the pipeline ID (basically a build number) is used for the version. You can change that to SemVer or whatever you prefer. The commit message and user triggering the build are added as part of the deployment.


This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.

See how we can help you monitor your website for crashes Monitor your website