Search code examples
jenkinsjenkins-pipelinejenkins-groovyjenkins-job-dsl

Declarative pipeline - Running a shell command


I have a jenkins pipeline script that I am updating wish to use the following shell command:

sh script: """
  export PATH=\"${PATH}\":\"${WORKSPACE}\"
  BASE_DIR=$(dirname $0)
  source "${BASE_DIR}/shellscript.sh"
                               
  helm uninstall ${helmReleaseName}  --namespace ${kubenamespace} 
"""
             

And the result always is:

Errors encountered validating Jenkinsfile:

I've played around with it. But it fails the validation? The question is why?

Thanks


Solution

  • Declarative pipeline with 'sh' step will look like:

    stage ("Preparing") {
        steps {
            sh'''
              export PATH=\"${PATH}\":\"${WORKSPACE}\"
              BASE_DIR=$(dirname $0)
              source "${BASE_DIR}/shellscript.sh"
                                   
              helm uninstall ${helmReleaseName}  --namespace ${kubenamespace}
            '''
        }
    }
    

    Take a look here