doc/ci/environments/external_deployment_tools.md
{{< details >}}
{{< /details >}}
While GitLab offers a built-in deployment solution, you might prefer to use an external deployment tool, such as Heroku or ArgoCD. GitLab can receive deployment events from these external tools and allows you to track the deployments within GitLab. For example, the following features are available by setting up tracking:
[!note] Some of the features are not available because GitLab can't authorize and leverage those external deployments, including Protected Environments, Deployment Approvals, Deployment safety, and Deployment rollback.
External deployment tools usually offer a webhook to execute an additional API request when deployment state is changed. You can configure your tool to make a request to the GitLab Deployment API. Here is an overview of the event and API request flow:
running status.success.failed.[!note] You can create a project access token for the GitLab API authentication.
You can use ArgoCD webhook to send deployment events to GitLab Deployment API.
Here is an example setup that creates a success deployment record in GitLab when ArgoCD successfully deploys a new revision:
Create a new webhook. You can save the following manifest file and apply it by kubectl apply -n argocd -f <manifiest-file-path>:
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
trigger.on-deployed: |
- description: Application is synced and healthy. Triggered once per commit.
oncePer: app.status.sync.revision
send:
- gitlab-deployment-status
when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
template.gitlab-deployment-status: |
webhook:
gitlab:
method: POST
path: /projects/<your-project-id>/deployments
body: |
{
"status": "success",
"environment": "production",
"sha": "{{.app.status.operationState.operation.sync.revision}}",
"ref": "main",
"tag": "false"
}
service.webhook.gitlab: |
url: https://gitlab.com/api/v4
headers:
- name: PRIVATE-TOKEN
value: <your-access-token>
- name: Content-type
value: application/json
Create a new subscription in your application:
kubectl patch app <your-app-name> -n argocd -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-deployed.gitlab":""}}}' --type merge
[!note] If a deployment wasn't created as expected, you can troubleshoot with
argocd-notificationstool. For example,argocd-notifications template notify gitlab-deployment-status <your-app-name> --recipient gitlab:argocd-notificationstriggers API request immediately and renders an error message from GitLab API server if any.