Skip to content
Latchkey

How to Deploy With Helm in Bitbucket Pipelines

Run helm upgrade --install with --atomic --wait so the release is rolled back automatically if the new pods never become ready.

Helm makes a Kubernetes deploy a single declarative command. Pass the new image tag with --set, and use --atomic so a failed upgrade reverts to the previous revision instead of leaving the release broken.

Steps

  • Provide cluster access (kubeconfig from a secured variable).
  • Run helm upgrade --install <release> <chart> with --set image.tag=<tag>.
  • Add --atomic --wait --timeout 5m so failures roll back cleanly.
  • Optionally helm history after to confirm the new revision.

Pipeline

bitbucket-pipelines.yml
image: alpine/helm:3.15.2
pipelines:
  branches:
    main:
      - step:
          name: Helm deploy
          deployment: production
          script:
            - mkdir -p $HOME/.kube && echo "$KUBECONFIG_B64" | base64 -d > $HOME/.kube/config
            - >
              helm upgrade --install web ./charts/web
              --namespace prod
              --set image.repository=$IMAGE_REPO
              --set image.tag=$BITBUCKET_COMMIT
              --atomic --wait --timeout 5m
            - helm history web -n prod --max 3

Gotchas

  • --atomic implies --wait; if pods do not become ready in --timeout, Helm rolls back.
  • Pin the Helm image tag so a chart that worked yesterday is not broken by a Helm major bump.
  • Keep secrets out of --set on the command line; use --values with a secured file.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →