【问题标题】:Run helm in jenkins pipeline在詹金斯管道中运行掌舵
【发布时间】:2021-05-29 15:31:52
【问题描述】:

我在 value.yaml 文件中添加了 helm 作为 podtemplate

 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"

所以我想在管道中运行 helm

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

但我有错误

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

Helm 和 Kubernetes 版本

Helm 版本:

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

Kubernetes 版本:

$ 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"}

图表的哪个版本

发生了什么: /home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh:1:/home/jenkins/workspace/coverwhale@tmp/durable-4d1fbfd5/script.sh:掌舵:未找到

您预期会发生什么: 运行掌舵图

管道代码

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"
             }
            }
        }
 }
}

【问题讨论】:

  • 你能说出你在管道脚本中的代理是什么吗?
  • @NisargShah 我已经用管道代码更新了帖子
  • 检查 helm 是否安装在 Jenkins 服务器中
  • 是的,好像没有安装,但是我不知道在jenkins节点中安装helm的方法
  • 您能否检查一下您是否能够在 jenkins 工作区中手动访问 helm 命令,即 /var/lib/jenkins/workspace ?只需尝试在给定路径内运行helm version 命令。如果您无法访问,请尝试使用sudo 访问。

标签: jenkins kubernetes jenkins-pipeline kubernetes-helm


【解决方案1】:

您也可以在运行 jenkins 管道的实例上安装 helm

stage("helm install"){
steps{
    echo "Helm install"      
    sh 'curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl'       
    sh 'curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" '
    sh 'sudo cp kubectl /usr/bin' 
    sh 'sudo chmod +x /usr/bin/kubectl'
    sh 'wget https://get.helm.sh/helm-v3.6.1-linux-amd64.tar.gz'
    sh 'ls -a'
    sh 'tar -xvzf helm-v3.6.1-linux-amd64.tar.gz'
    sh 'sudo cp linux-amd64/helm /usr/bin'
  }
}

【讨论】:

    【解决方案2】:

    我已经通过将 containerTemplate 添加到代理来解决它。

      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"
                   }    
                 }
            } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多