GitLab CI Integration
Learn how to automate your Helm chart publishing workflow using GitLab CI/CD.
Pipeline Configuration
Create the following pipeline configuration in your repository:
.gitlab-ci.yml
variables:
HELM_VERSION: "3.12.0"
stages:
- lint
- test
- publish
.helm_setup: &helm_setup |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh --version $HELM_VERSION
helm repo add helmbay https://charts.helmbay.com/$HELMBAY_REPO
helm repo update
lint:
stage: lint
image: alpine/helm:$HELM_VERSION
script:
- |
for chart in charts/*; do
if [ -d "$chart" ]; then
helm lint "$chart"
fi
done
test:
stage: test
image: alpine/helm:$HELM_VERSION
services:
- docker:dind
variables:
KUBECONFIG: /etc/deploy/config
before_script:
- *helm_setup
script:
- |
for chart in charts/*; do
if [ -d "$chart" ]; then
helm install test-release "$chart" --dry-run
fi
done
publish:
stage: publish
image: alpine/helm:$HELM_VERSION
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
before_script:
- *helm_setup
script:
- |
for chart in charts/*; do
if [ -d "$chart" ]; then
helm package "$chart"
helm push ${chart##*/}-*.tgz oci://charts.helmbay.com/$HELMBAY_REPO
fi
done
Required Variables
Configure the following variables in your GitLab CI/CD settings:
Name | Type | Description |
---|---|---|
HELMBAY_TOKEN Required | Variable | API token for authentication |
HELMBAY_REPO Required | Variable | Repository name in Helmbay |
Best Practices
Pipeline Structure
- Use stages for organized workflow
- Implement proper caching
- Keep configuration DRY with anchors
- Use specific image versions
Security
- Use GitLab CI/CD variables
- Implement protected branches
- Scan for vulnerabilities
- Regular credential rotation
Testing
- Run comprehensive tests
- Validate chart templates
- Test with multiple K8s versions
- Archive test artifacts
Examples
Advanced Pipeline
Example with matrix testing and parallel jobs
.gitlab-ci.yml
include:
- template: Security/Container-Scanning.gitlab-ci.yml
.test_template: &test_definition
stage: test
script:
- helm dependency build
- helm template --debug .
- helm install --dry-run --debug .
test:k8s-1.24:
<<: *test_definition
image: alpine/helm:3.12.0
variables:
KUBE_VERSION: "1.24.0"
test:k8s-1.25:
<<: *test_definition
image: alpine/helm:3.12.0
variables:
KUBE_VERSION: "1.25.0"
Troubleshooting
helm registry login -u _ -p $HELMBAY_TOKEN charts.helmbay.com
timeout: 2h
gitlab-runner cache-clear
Next Steps
Learn how to integrate with other CI/CD platforms.