Helm Set Docker Image Tag Dynamically

1/14/2020

I am pushing Docker images to our private registry via Jenkins with the following command:

def dockerImage = docker.build("repo/myapp:${env.BUILD_NUMBER}")

(BUILD_NUMBER increases after every build.)

Because I am new to using Helm, I could not decide how should I give the tag for images in values.yaml.

I would like to deploy my app to multiple environments such as:

  • dev
  • test
  • prod

Let's say I was able to deploy my app via Helm to dev, and the latest BUILD_NUMBER is:

  • 100 for dev
  • 101 for test
  • 102 for prod

What should be the tag value, then?

 image:
  repository: registryt/myrepo/image
  tag: 
-- semural
jenkins
kubernetes
kubernetes-helm

1 Answer

1/14/2020

You should put "some" tag into your values.yaml which will act as the default tag. Each Helm Chart has it, you can check the official Helm Charts here.

Now, you have two options on how to act with the different environments.

Option 1: Command line parameters

While installing your Helm Chart, you can specify the tag name dynamically with --set. For example:

$ helm install --set image.tag=12345 <your-chart-name>

Option 2: Separate values.yaml files

You can store separate values.yaml in your repository, like:

values.dev.yaml
values.prod.yaml

Then, update the correct values in your Jenkins pipeline.

-- RafaƂ Leszko
Source: StackOverflow