Skip to main content
The ArgoCD job agent creates and syncs ArgoCD Applications, enabling GitOps-style deployments with automatic health verification.

How It Works

  1. Ctrlplane renders an ArgoCD Application from your template
  2. The Application is created or updated via ArgoCD API
  3. ArgoCD syncs the application to Kubernetes
  4. Ctrlplane verifies the application reaches Healthy + Synced status
  5. Job is marked successful when verification passes

Prerequisites

  • ArgoCD server with API access
  • API token with application create/update permissions
  • Network connectivity from Ctrlplane to ArgoCD

Configuration

Job Agent Setup

Create a job agent with type argo-cd:
type: JobAgent
name: argocd
agentType: argo-cd

Deployment Configuration

type: Deployment
name: api-service
jobAgent: argocd
jobAgentConfig:
  serverUrl: argocd.example.com:443
  apiKey: "{{.variables.argocd_token}}"
  template: |
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: {{.deployment.slug}}-{{.environment.name}}
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: https://github.com/your-org/your-repo
        targetRevision: {{.version.tag}}
        path: k8s/{{.environment.name}}
      destination:
        server: {{.resource.config.server}}
        namespace: {{.resource.config.namespace}}
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
FieldRequiredDescription
serverUrlYesArgoCD server URL (host:port)
apiKeyYesArgoCD API token
templateYesGo template for ArgoCD Application

Template Context

The template has access to all job context. Variables are accessed using Go template syntax: {{.variable.property}}. The job context is derived from the resources returned by the deployment selector (and narrowed by the environment selector), so the data available to the template reflects that specific target.

Top-Level Variables

VariableDescription
.jobCurrent job details
.versionVersion being deployed (shortcut)
.deploymentUser-defined deployment configuration and properties
.environmentUser-defined environment you deploy into and its properties
.resourceUser-defined resource you deploy against and its properties
.variablesMerged deployment variables (key-value strings)

Resource Properties

Each job invocation is tied to a specific resource instance returned by your selector, so the .resource values can differ for every ArgoCD template invocation.
PropertyTypeDescription
.resource.idstringUnique resource ID
.resource.namestringDisplay name
.resource.identifierstringUnique identifier within workspace
.resource.kindstringResource kind (e.g., KubernetesCluster)
.resource.versionstringResource schema version
.resource.configobjectArbitrary configuration data
.resource.metadatamap[string]stringKey-value metadata labels
.resource.workspaceIdstringParent workspace ID
.resource.providerIdstringResource provider ID (if any)
.resource.createdAttimestampCreation timestamp
.resource.updatedAttimestampLast update timestamp
.resource.lockedAttimestampLock timestamp (if locked)

Deployment Properties

Each job invocation is tied to a specific deployment, so .deployment values can differ for every ArgoCD template invocation.
PropertyTypeDescription
.deployment.idstringUnique deployment ID
.deployment.namestringDisplay name
.deployment.slugstringURL-friendly identifier
.deployment.descriptionstringOptional description
.deployment.systemIdstringParent system ID
.deployment.jobAgentIdstringAssociated job agent ID
.deployment.jobAgentConfigobjectJob agent configuration
.deployment.resourceSelectorobjectResource selector for targeting

Environment Properties

Each job invocation is tied to a specific environment, so .environment values can differ for every ArgoCD template invocation.
PropertyTypeDescription
.environment.idstringUnique environment ID
.environment.namestringDisplay name
.environment.descriptionstringOptional description
.environment.systemIdstringParent system ID
.environment.resourceSelectorobjectResource selector
.environment.createdAttimestampCreation timestamp

Version Properties

Access via .version:
PropertyTypeDescription
.version.idstringUnique version ID
.version.tagstringVersion tag (e.g., v1.2.3)
.version.namestringDisplay name
.version.messagestringOptional commit/release message
.version.statusstringVersion status
.version.configobjectVersion-specific configuration
.version.metadatamap[string]stringVersion metadata
.version.jobAgentConfigobjectVersion-level job agent config
.version.deploymentIdstringParent deployment ID
.version.createdAttimestampCreation timestamp

Job Properties

PropertyTypeDescription
.job.idstringUnique job ID
.job.statusstringCurrent status
.job.messagestringStatus message
.job.externalIdstringExternal system reference
.job.metadatamap[string]stringJob metadata
.job.jobAgentIdstringExecuting job agent ID
.job.releaseIdstringAssociated release ID
.job.createdAttimestampCreation timestamp
.job.startedAttimestampExecution start timestamp
.job.completedAttimestampCompletion timestamp
.job.updatedAttimestampLast update timestamp

Variables

The .variables map contains all resolved deployment variables as strings:
template: |
  metadata:
    annotations:
      replicas: "{{.variables.replica_count}}"
      db-host: "{{.variables.database_host}}"

Accessing Nested Config

Resource and version configs are arbitrary objects. Access nested properties:
template: |
  spec:
    destination:
      server: {{.resource.config.cluster_url}}
      namespace: {{.resource.config.namespaces.app}}
    source:
      helm:
        parameters:
          - name: image.tag
            value: {{.version.config.imageTag}}

Template Functions

The template supports Sprig functions:
template: |
  apiVersion: argoproj.io/v1alpha1
  kind: Application
  metadata:
    name: {{ .deployment.slug | lower | replace "_" "-" }}
    labels:
      version: {{ .version.tag | trunc 63 }}
      deployed-at: {{ now | date "2006-01-02" }}

Automatic Verification

When an ArgoCD Application is created, Ctrlplane automatically starts a verification that checks:
  • Application sync status is Synced
  • Application health status is Healthy or Progressing
The verification polls the ArgoCD API every 10 seconds for 5 iterations.

Example: Multi-Environment Setup

type: Deployment
name: frontend
jobAgent: argocd
jobAgentConfig:
  serverUrl: "{{.variables.argocd_server}}"
  apiKey: "{{.variables.argocd_token}}"
  template: |
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: frontend-{{.environment.name | lower}}
      namespace: argocd
      labels:
        app: frontend
        env: {{.environment.name | lower}}
        version: {{.version.tag}}
      finalizers:
        - resources-finalizer.argocd.argoproj.io
    spec:
      project: {{.environment.name | lower}}
      source:
        repoURL: https://github.com/your-org/frontend
        targetRevision: {{.version.tag}}
        path: deploy/{{.environment.name | lower}}
        helm:
          valueFiles:
            - values.yaml
            - values-{{.environment.name | lower}}.yaml
          parameters:
            - name: image.tag
              value: {{.version.tag}}
            - name: replicas
              value: "{{.resource.config.replicas | default 2}}"
      destination:
        server: {{.resource.config.cluster_url}}
        namespace: frontend
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true

Example: Kustomize Overlay

template: |
  apiVersion: argoproj.io/v1alpha1
  kind: Application
  metadata:
    name: {{.deployment.slug}}-{{.resource.identifier}}
    namespace: argocd
  spec:
    project: default
    source:
      repoURL: https://github.com/your-org/{{.deployment.slug}}
      targetRevision: {{.version.tag}}
      path: overlays/{{.environment.name}}
      kustomize:
        images:
          - {{.deployment.slug}}={{.variables.registry}}/{{.deployment.slug}}:{{.version.tag}}
    destination:
      server: {{.resource.config.server}}
      namespace: {{.deployment.slug}}

Troubleshooting

Application not syncing

  • Check ArgoCD server logs
  • Verify the repository is accessible from ArgoCD
  • Check the target revision exists

Authentication errors

  • Verify the API token is valid
  • Check token has correct permissions
  • Ensure serverUrl includes the correct port

Verification failing

  • Check ArgoCD Application status in the UI
  • Review sync errors in ArgoCD
  • Verify destination cluster is accessible