Use a commit ID as a parameter on an ArgoCD ApplicationSet

argocd commit id build environment Application

2 min read | by Jordi Prats

When defining ArgoCD Applicacions it can come handy to be able to use it's commit id as a variable. This comes specially handy when using ApplicacionSets

There are several variables we can use (see Build environment), for getting the commit id we can use ARGOCD_APP_REVISION.

For example, if we have a build system that uses the commit id for setting the container tag, we can use the parameters attribute to feed it to the image.tag value of a helm chart as follows:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: pet2cattle-versions
  namespace: argocd
spec:
  generators:
  - list:
      elements:
      - target: 1.0.0
        instance: v1
      - target: 2.0.0
        instance: v2
  template:
    metadata:
      name: pet2cattle-{{ instance }}
    spec:
      project: default
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
      source:
        repoURL: ssh://git@github.com:jordiprats/helm-pet2cattle.git
        path: .
        targetRevision: "{{ target }}"
        helm:
          values: |
            ingress:
              hosts:
                - "{{ instance }}.pet2cattle.com
          parameters:
          - name: image.tag
            value: $ARGOCD_APP_REVISION
      destination:
        server: https://kubernetes.default.svc
        namespace: pet2cattle

Posted on 09/06/2022