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

<p>For instance:</p>

<pre><code>parameters {
    string(
        name: 'DEPLOY_BUILD_NUMBER',
        defaultValue: "${BUILD_NUMBER}",
        description: 'Fresh Build and Deploy OR Deploy Previous Build Number'
    )
}
</code></pre>

CC BY-SA 4.0
2019-02-26T16:50:49.360Z
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}`
rp346
CC BY-SA 4.0
2019-02-25T22:01:52.733Z
2019-02-25T22:01:52.733Z
jayhendren
<p>I am trying to crate parameters field which is default to current build no.</p>

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

<p>But it looks like the assignment of <code>BUILD_NUMBER</code> env var to parameter <code>DEPLOY_BUILD_NUMBER</code> is not happening.</p>

<p>even following one didn't help</p>

<pre><code>steps {
        script {
            if (params.DEPLOY_BUILD_NUMBER == null){
                DEPLOY_BUILD_NUMBER = env.BUILD_NUMBER
            }
        }
}
</code></pre>

<p>Is there any other way to do this ?</p>

CC BY-SA 4.0
2019-02-25T17:40:44.447Z
I can only guess that the BUILD_NUMBER env var is not yet populated in the stage of reading the build parameters.
Itai Ganot
<jenkins><jenkins-pipeline><jenkinsfile><jenkins2>
Jenkins parameters default to env variable?
rp346
# Jenkins parameters default to env variable?

(Asked by: username_0 on 2019-02-25)

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 ?

**Tags:** jenkins, jenkins-pipeline, jenkinsfile, jenkins2

> **Comments:**
> **username_1**: I can only guess that the BUILD_NUMBER env var is not yet populated in the stage of reading the build parameters.  

---

## 1 answers

### Answer by username_2 on 2019-02-25. Score: 3 | Accepted answer

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'
    )
}

> **Comments:**
> **username_0**: 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}`  

---

