Update version in pom with helm

Viewed 451

I would like to have to update only one application version field. Currently in maven's pom.xml I have the version as usual :

<version>1.1.0</version>

I would like that field in inherit from Helm's Chart.yaml appVersion property.

appVersion: 1.1.0

Is this possible to be done via Helm templating or some other way?

1 Answers

You can use the maven-resources-plugin in validate phase here to copy the helm chart from one folder to other. Let's say you have helm chart with placeholder in template folder and while running helm command you can point to app folder.

So the values file in template folder can contain placeholder like

image:
  tag: application-${project.version}

pom.xml should include a maven-resources-plugin with filtering enabled.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <goals>
        <goal>resources</goal>
    </goals>
    <executions>
        <execution>
            <id>copy-resources-helm-deployment</id>
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>k8s/app</outputDirectory>
                <resources>
                    <resource>
                        <directory>k8s/app/values_templates</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

when mvn clean process-resources is executed it would copy the values file in k8s/app (output directory) with project version replaced as the pom version.

Refer this for more info on maven resource plugin https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Related