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 ?

rp346
  • 135
  • 2
  • 6

1 Answers1

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'
    )
}
jayhendren
  • 3,022
  • 8
  • 16