gitchartskubernetes-helmargocd

ArgoCD: Provide git commit SHA to Helm values


Assume you have an Application spec inside a cluster which is manage by ArgoCD, like:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: foo-app
  namespace: argocd
spec:
  destination:
    name: some-cluster
    namespace: foo-namespace
  project: default
  source:
    path: kubernetes/helm
    repoURL: https://github.com/my/great-project.git
    targetRevision: HEAD

Now assuming inside the Helm Chart I need access to the checked out Git commit SHA which was used to get the Helm Chart inside kubernetes/helm. Like to reference the image name my-registry.com/my/great-project:<COMMIT_SHA>.

How to achieve this?


Solution

  • According to build environment, you should be able to use the environment variable ARGOCD_APP_REVISION on your Helm chart.

    To use those build environment variables with Helm, you can do as following for instance:

      spec:
        source:
          helm:
            parameters:
            - name: revision
              value: $ARGOCD_APP_REVISION
    

    Source: https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#build-environment