Jenkins parameters default to env variable?

6,211

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'
    )
}
Share:
6,211

Related videos on Youtube

roy
Author by

roy

Updated on September 18, 2022

Comments

  • roy
    roy over 1 year

    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 ?

  • roy
    roy about 5 years
    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}