"Is this ticket in production yet?" is easy to answer when a pipeline deploys your code, because Jira's deployment view is filled by tools such as GitHub Actions, Jenkins and Azure DevOps.
With GitOps it stays empty. Argo CD pulls the change into the cluster, so no pipeline step ever tells Jira that a deployment happened.
This article shows how to close that gap yourself, using only Argo CD's built-in notifications and Jira's Deployments API. At the end there is a ready-made app, if you would rather not maintain the pieces.
What you need
- Argo CD 2.3 or later. The notifications controller is included.
- Jira Cloud, with permission to create OAuth credentials or install an app.
- Commit messages that contain the work item key, for example
KAN-12 raise the timeout.
The idea
- Argo CD finishes a sync.
- A notification trigger fires and posts a small JSON document to a webhook.
- The receiver turns it into a deployment record and sends it to Jira with
POST /rest/deployments/0.1/bulk. - Jira shows the deployment on every work item whose key appeared in the commit message.
Step 1: Send sync events from Argo CD
Add a webhook service, a template and three triggers to argocd-notifications-cm:
data: service.webhook.jira: | url: $jira-webhook-url headers: - name: Authorization value: $jira-webhook-auth - name: Content-Type value: application/json template.jira-deployment: | webhook: jira: method: POST body: | {{- $rev := or .app.status.operationState.operation.sync.revision .app.status.sync.revision -}} {{- $commit := call .repo.GetCommitMetadata $rev -}} { "app": {{ .app.metadata.name | toJson }}, "project": {{ .app.spec.project | toJson }}, "revision": {{ $rev | toJson }}, "phase": {{ .app.status.operationState.phase | toJson }}, "health": {{ .app.status.health.status | toJson }}, "commitMessage": {{ $commit.Message | toJson }}, "startedAt": {{ .app.status.operationState.startedAt | toJson }}, "finishedAt": {{ .app.status.operationState.finishedAt | toJson }}, "namespace": {{ .app.spec.destination.namespace | toJson }}, "cluster": {{ or .app.spec.destination.name .app.spec.destination.server | toJson }}, "url": {{ printf "%s/applications/%s" .context.argocdUrl .app.metadata.name | toJson }} } trigger.on-sync-running: | - when: app.status.operationState != nil and app.status.operationState.phase in ['Running'] oncePer: app.status.operationState.startedAt send: [jira-deployment] trigger.on-sync-succeeded: | - when: app.status.operationState != nil and app.status.operationState.phase in ['Succeeded'] oncePer: app.status.operationState.startedAt send: [jira-deployment] trigger.on-sync-failed: | - when: app.status.operationState != nil and app.status.operationState.phase in ['Error', 'Failed'] oncePer: app.status.operationState.startedAt send: [jira-deployment] Two details matter here:
- Use
toJsonon every value. A commit message with a quote or a line break otherwise produces invalid JSON. -
repo.GetCommitMetadatagives you the commit message. That is where the work item keys come from, with no extra access to your Git provider.
Then subscribe each Application with annotations:
metadata: annotations: notifications.argoproj.io/subscribe.on-sync-running.jira: "" notifications.argoproj.io/subscribe.on-sync-succeeded.jira: "" notifications.argoproj.io/subscribe.on-sync-failed.jira: "" Step 2: Turn the event into a Jira deployment
The receiver has four jobs.
Find the work item keys. A pattern such as \b[A-Z][A-Z0-9]{1,9}-[1-9][0-9]*\b over the commit message finds KAN-12. It also finds keys in merge commits that include a branch name.
Map the state. Argo CD's Running becomes in_progress, Succeeded becomes successful, and Failed or Error becomes failed.
Pick the environment type. Jira wants production, staging, testing or development. The namespace or cluster name usually tells you.
Keep one sync as one deployment. Jira identifies a deployment by pipeline, environment and a sequence number. Use the sync's start time as that number, so the "running" and "succeeded" events update the same record.
Three things that went wrong for me
- A missing
argocdUrlrejects the whole deployment. Without that setting, the template produces%!s(<nil>)/applications/my-app. Jira refuses it as an invalid URL, and it refuses the entire record, not just the link. Setcontext.argocdUrl, and validate the URL in the receiver. - A 5xx answer makes Argo CD retry. If Jira rejects the data, answer with a 4xx. Otherwise Argo CD sends the same rejected data three more times.
- The deployment appears after about a minute. Jira accepts the call at once and processes it in the background, so do not conclude it failed too early.
One known limit
Argo CD exposes the message of the commit it synced, not the commits before it. If several merges are synced together, the work items from the earlier commits are missed.
If you would rather not build it
I packaged this as a Jira app that runs on Atlassian's Forge platform. It has a setup page that creates the token and fills in the Argo CD config for you, and it needs no agent in the cluster and no inbound access.
It works today as a prototype, and I am looking for a few teams to test it: https://jira-apps-dev.bitbucket.io
