-1

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

mac
  • 1,479
  • 3
  • 11
  • 21
  • More information is needed regarding the exact error, but looks like you need to escape the **$** signs that are not used for string Interpolation. `BASE_DIR=\$(dirname \$0)` – Noam Helmer Jun 27 '21 at 11:12

1 Answers1

1

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

Dmitriy Tarasevich
  • 1,082
  • 5
  • 6
  • If you use single quotes **'''** instead of double quotes **"""** the String Interpolation will not work and the parameters will not be evaluated, so multi line double quotes should be used. – Noam Helmer Jun 27 '21 at 11:09
  • It worked for me by changing double quotes to single quotes and the parameters were evaluated. – mac Jun 27 '21 at 17:34