Specify Helm Chart Name use for upgrade install command

1/19/2020

I am using Helm 3 and when I run below command in Jenkins pipeline.

  + helm upgrade --install road-dashboard -f values.dev.yaml --namespace dev

I received an below error.

Error: "helm upgrade" requires 2 arguments

Probably I should specify chart name as well.But I have some confusion because of new for using Helm.

1.How should I specify the chart name. It has to be directory or any chart name that I can specify.My app tree structure as below.

 +-- helm\road-dashboard
    |       +--charts
    |       +-- templates
    |       |   \-- ...
    |       +-- Chart.yaml
    |       +-- values.dev.yaml     # dev override values
    |       +-- values.stage.yaml   # stage override values
    |       +-- values.prod.yaml    # production override values

2.I would like to run helm lint command before deployment.My helm chart directory in Jenkins:/home/ubuntu/workspace/road-dashboard/helm/road-dashboard. So what is the best practice to change directory only for helm lint command and return existing working directory for helm --upgrade install command which should be /home/ubuntu/workspace/road-dashboard. Below is the script that but not sure this is suitable for best practices.

        stage('Deploy to dev'){
        when{
            beforeAgent true
            expression{return env.GIT_BRANCH == "origin/develop"}
        }
        steps{
            dir('/home/ubuntu/workspace/road-dashboard/helm/road-dashboard'){
                sh "helm lint"
            }
            script{
                def namespace = "dev"
                def ENV = "dev"

                withCredentials([file(credentialsId: 'mbtkubeconfig', variable: 'config')]){

                    sh """
                        export KUBECONFIG=\${config}
-- semural
jenkins
jenkins-pipeline
kubernetes-helm

1 Answer

1/19/2020

You can get the release and chart name by running the "helm list" command if it is already deployed.

The syntax for helm upgrade is -

helm upgrade [RELEASE] [CHART] [flags]

so in your case

helm upgrade [RELEASE] [CHART] --install -f values.yaml .. ...

Regarding the second question -

I would suggest you stay in the Jenkins job workspace directory and the switch directories as per your need. Any step inside the dir block will use this directory as current and any relative path will use it as the base path.

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#dir-change-current-directory

Also, defining a separate stage for lint and actual deployment would be a good idea; so you get a clear indication which stage failed in case of failures.

-- Pankaj
Source: StackOverflow