1

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 ?

1
  • 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, 2019 at 17:40

1 Answer 1

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'
    )
}
1
  • 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, 2019 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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