1 year ago

#76295

test-img

Mukund Ranjan

env variable as defaultValue in Jenkinsfile

pipline{
   agent any
       environment{
               GIT_HASH = "${GIT_COMMIT.substring(0, 7)}"
                }
       parameters{
                 string(
                      name: 'bld_ver',
                      defaultValue: "${env.GIT_HASH}",
                      description: "enter version"
                     )
            }

In above code from Jenkinsfile, If user is not providing bld version then 7 letters of hash will be used as default value. But it is throwing below error:

script.sh: line 6: ${env.GIT_HASH}: bad substitution

Although If I print it using

echo ${env.GIT_HASH} 

It is printing correctly, what could be the issue here. How can I pass default value as env variable?.

jenkins-pipeline

jenkins-groovy

0 Answers

Your Answer

Accepted video resources