Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 470 of 8027. Package Management and AutomationFree lesson

Automating Chart Versioning in CI Pipelines

Integrate automated version bumping scripts into your CI workflow to ensure every merged change creates a unique, deployable chart artifact.

In this lesson, you will learn how to eliminate manual version updates by embedding automated SemVer logic directly into your CI pipeline.

The Problem with Manual Versioning

When developers push code, manually updating the version field in Chart.yaml is prone to human error. If you forget to increment the version, your CI process may attempt to push an identical artifact to your registry, causing a conflict or overwriting an existing release. To achieve a truly continuous delivery flow, the CI pipeline itself must detect changes and calculate the next valid version.

Automating with the Pipeline

The core concept is to treat your CI runner as a version-aware agent. Instead of hardcoding versions, your pipeline should execute a script during the build phase that parses the current version from the Chart.yaml file, calculates the next patch version based on your deployment strategy, and updates the file before packaging.

For example, using a simple shell command in your pipeline, you can update the version dynamically:

# Extract current version and increment patch version
CURRENT_VERSION=$(grep 'version:' Chart.yaml | awk '{print $2}')
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')

# Update Chart.yaml using yq (a common tool for YAML processing)
yq eval ".version = \"$NEW_VERSION\"" -i Chart.yaml

# Package the chart for the registry
helm package . --version $NEW_VERSION

Ensuring Unique Artifacts

Once the pipeline has updated the Chart.yaml, the helm package command generates a .tgz artifact with the new version string. By piping this process into your automated push step (e.g., helm push mychart-$NEW_VERSION.tgz oci://my-registry), you ensure that every successful merge creates a unique, immutable artifact ready for deployment.

This approach maintains the integrity of your chart history and ensures that your Kubernetes clusters always pull the precise, intended version of your application configuration. By delegating the "increment" task to your automation, you remove the bottleneck of manual version management and ensure your registry remains a reliable source of truth.

Key Takeaway: Automating version bumps within the CI pipeline prevents collision errors and guarantees that every code change results in a unique, deployable, and traceable Helm chart artifact.