0
votes

I have added helm as podtemplate in value.yaml file

 podTemplates: 
    helm: |
      - name: helm
        label: jenkins-helm
        serviceAccount: jenkins
        containers:
          - name: helm
            image: lachlanevenson/k8s-helm:v3.1.1
            command: "/bin/sh -c"
            args: "cat"
            ttyEnabled: true
            privileged: true
            resourceRequestCpu: "400m"
            resourceRequestMemory: "512Mi"
            resourceLimitCpu: "1"
            resourceLimitMemory: "1024Mi"

so i want to run helm in pipeline as

     steps {
            container('helm') {
                sh "helm upgrade --install --force  ./helm"
            }
        }

but i got error

       /home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh: 1: /home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh: helm: not found

Version of Helm and Kubernetes:

Helm Version:

$ helm version
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}

Kubernetes Version:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:28:09Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:20:00Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

Which version of the chart:

What happened: /home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh: 1: /home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh: helm: not found

What you expected to happen: run helm chart

pipeline code

pipeline {

agent any

stages {

         stage('Initialize Docker'){
             steps {
                  script {
                       def docker = tool 'whaledocker'
                       echo "${docker}"
                       echo "${env.PATH}"
                       env.PATH = "${docker}/bin:${env.PATH}"
                       echo "${env.PATH}"
                  }
             }
        }
    
        stage('Checkout Source') {

             steps {
                 git url:'https://github.com/alialrabi/laravel-example.git', branch: 'uat', credentialsId: 'github'
             }
        }

        stage("Build image") {
      
            steps {
                 script {
                   myapp = docker.build("alialrabi/coverwhale:${env.BUILD_ID}")
                 }
            }
        }
    
 
        stage("Run Test") {
      
            steps {
                 script {
                      docker.image("alialrabi/coverwhale:${env.BUILD_ID}").inside {
                     //   sh 'composer install'  
                      //  sh 'php artisan test'
                      }
                 }
            }
        }
    

        stage("Push image") {
        
             steps {
                
                 script {
                     docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
                          myapp.push("latest")
                          myapp.push("${env.BUILD_ID}")
                     }
                 }
             }
        }

        stage('Deploy Uat') {
            
 
            steps {
                 script {
                echo "Done Uat"
                  sh "helm upgrade --install --force"
             }
            }
        }
 }
}
1
Can you tell what is your agent in pipeline script?Nisarg Shah
@NisargShah I have updated post with pipeline codeAli-Alrabi
Check if helm is installed in Jenkins ServerQuentin Merlin
yes,It seem it's not installed, but i don't know a way to install helm in jenkins nodeAli-Alrabi
Can you check whether you are able to manually access helm command inside jenkins workspace i.e. /var/lib/jenkins/workspace ? Just try running helm version command inside the given path. And if you are not able to access, then try accessing with sudo.Nisarg Shah

1 Answers

0
votes

I have solved it by add containerTemplate to agent.

  stage('Deploy dev') {
            
         agent {
           kubernetes {
                 containerTemplate {
                   name 'helm'
                   image 'lachlanevenson/k8s-helm:v3.1.1'
                   ttyEnabled true
                   command 'cat'
              }
            }
         }
            
            steps {
               container('helm') { 
                 sh "helm upgrade full-cover ./helm"
               }    
             }
        }