Jenkins Integration

Learn how to automate your Helm chart publishing workflow using Jenkins.

Pipeline Configuration

Create the following Jenkinsfile in your repository:

Jenkinsfile
pipeline {
  agent {
    docker {
      image 'alpine/helm:3.12.0'
      args '-u root'
    }
  }

  environment {
    HELMBAY_CREDS = credentials('helmbay-credentials')
    HELM_VERSION = '3.12.0'
  }

  stages {
    stage('Setup') {
      steps {
        sh '''
          helm repo add helmbay https://charts.helmbay.com/$HELMBAY_REPO
          helm repo update
        '''
      }
    }

    stage('Lint') {
      steps {
        sh '''
          for chart in charts/*; do
            if [ -d "$chart" ]; then
              helm lint "$chart"
            fi
          done
        '''
      }
    }

    stage('Test') {
      steps {
        sh '''
          for chart in charts/*; do
            if [ -d "$chart" ]; then
              helm install test-release "$chart" --dry-run
            fi
          done
        '''
      }
    }

    stage('Publish') {
      when {
        branch 'main'
      }
      steps {
        sh '''
          for chart in charts/*; do
            if [ -d "$chart" ]; then
              helm package "$chart"
              helm push ${chart##*/}-*.tgz oci://charts.helmbay.com/${{ secrets.HELMBAY_REPO }}
            fi
          done
        '''
      }
    }
  }

  post {
    always {
      cleanWs()
    }
  }
}

Credentials Setup

Configure the following credentials in Jenkins:

Name Type Description Scope
helmbay-credentials Required Username with password Helmbay API credentials Global
HELMBAY_REPO Required Secret text Repository name in Helmbay Global

Best Practices

Pipeline Structure

  • Use declarative pipeline syntax
  • Implement proper error handling
  • Clean workspace after builds
  • Use Docker agents for consistency

Security

  • Use Jenkins credentials store
  • Implement approval gates
  • Scan for vulnerabilities
  • Rotate credentials regularly

Testing

  • Run comprehensive tests
  • Validate chart templates
  • Test with multiple K8s versions
  • Archive test results

Examples

Shared Library

Reusable Jenkins pipeline library for Helm charts

vars/helmDeploy.groovy
def call(Map config) {
  def chart = config.chart ?: '.'
  def namespace = config.namespace ?: 'default'
  def release = config.release ?: 'release'

  sh """
    helm upgrade --install ${release} ${chart} \
      --namespace ${namespace} \
      --create-namespace \
      --wait \
      --timeout 5m
  """
}

Multi-Branch Pipeline

Configuration for multi-branch pipeline setup

Jenkinsfile
pipeline {
  agent any
  
  options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
    disableConcurrentBuilds()
  }

  stages {
    stage('Determine Version') {
      steps {
        script {
          env.CHART_VERSION = sh(
            script: "yq e '.version' charts/*/Chart.yaml",
            returnStdout: true
          ).trim()
        }
      }
    }

    stage('Build and Test') {
      parallel {
        stage('Lint') {
          steps {
            sh 'helm lint charts/*'
          }
        }
        stage('Unit Tests') {
          steps {
            sh 'helm test charts/*'
          }
        }
      }
    }
  }
}

Troubleshooting

Docker agent issues
Verify Docker socket mounting
docker run --rm alpine/helm:3.12.0 version
Credential access
Check credential binding
echo $HELMBAY_CREDS | helm registry login -u _ --password-stdin charts.helmbay.com
Workspace cleanup
Force workspace cleanup
rm -rf .* * || true

Next Steps

Explore advanced Jenkins pipeline features and optimizations.