0

I am trying to crate parameters field which is default to current build no.

parameters {
    string(
        name: 'DEPLOY_BUILD_NUMBER',
        defaultValue: '${BUILD_NUMBER}',
        description: 'Fresh Build and Deploy OR Deploy Previous Build Number'
    )
}

But it looks like the assignment of BUILD_NUMBER env var to parameter DEPLOY_BUILD_NUMBER is not happening.

even following one didn't help

steps {
        script {
            if (params.DEPLOY_BUILD_NUMBER == null){
                DEPLOY_BUILD_NUMBER = env.BUILD_NUMBER
            }
        }
}

Is there any other way to do this ?

  • I can only guess that the BUILD_NUMBER env var is not yet populated in the stage of reading the build parameters. – Itai Ganot Feb 25 at 17:40
3

You need to use double quotes instead of single quotes. Single-quoted strings don't perform string interpolation.

For instance:

parameters {
    string(
        name: 'DEPLOY_BUILD_NUMBER',
        defaultValue: "${BUILD_NUMBER}",
        description: 'Fresh Build and Deploy OR Deploy Previous Build Number'
    )
}
  • after this change, echo "${DEPLOY_BUILD_NUMBER}" prints env.BUILD_NUMBER. How can I get actual value of env.BUILD_NUMBER, when I refer to ${DEPLOY_BUILD_NUMBER} – roy Feb 26 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.