Skip to main content

Deploy Argo CD

Synchronizes an existing Argo CD Application from a GitLab pipeline and waits for the application to become Synced and Healthy.

include:
- component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/deploy-argocd@$CI_COMMIT_SHA
inputs:
application: my-app
server: argocd.example.com
token-variable: ARGOCD_AUTH_TOKEN

The component uses the argocd CLI from the ci-tools tools image, reads the token from ARGOCD_AUTH_TOKEN, and runs argocd app sync only when automated sync is not enabled on the Application. It always waits for Synced and Healthy unless wait-enabled: false is set.

Set insecure: true for internal or self-signed Argo CD API servers where certificate validation is intentionally skipped.

Setup

Create a dedicated Argo CD local account for GitLab CI and allow it to read and sync the target Applications.

apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
accounts.gitlab-ci: apiKey
---
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
data:
policy.csv: |
p, role:gitlab-deploy, applications, get, default/my-app, allow
p, role:gitlab-deploy, applications, sync, default/my-app, allow
g, gitlab-ci, role:gitlab-deploy

Generate a token with argocd account generate-token --account gitlab-ci and store it as the masked CI/CD variable ARGOCD_AUTH_TOKEN. Set ARGOCD_SERVER or the component server input to the Argo CD API server hostname.

Inputs

NameDescriptionDefaultType
------------
applicationThe Argo CD Application name.string
insecureSkip Argo CD server TLS certificate verification.falseboolean
needsThe jobs that this job depends on.[]array
rulesRules that control when the deployment job runs.[{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH","when":"on_success"},{"when":"never"}]array
serverArgo CD API server. Defaults to ARGOCD_SERVER when unset.string
stageThe pipeline stage for the deployment job.deploystring
sync-enabledRun an explicit Argo CD sync before waiting.trueboolean
tagRunner tag for the deployment job.string
timeoutTimeout for sync and wait operations.15mstring
token-variableEnvironment variable that contains an Argo CD auth token.ARGOCD_AUTH_TOKENstring
wait-enabledWait for the Argo CD Application to become synced and healthy.trueboolean