Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-02-26T16:50:49.360Z
Answers: 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}`
Answers: rp346
Answers: CC BY-SA 4.0
Answers: 2019-02-25T22:01:52.733Z
Answers: 2019-02-25T22:01:52.733Z
Answers: jayhendren
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2019-02-25T17:40:44.447Z
Comments: I can only guess that the BUILD_NUMBER env var is not yet populated in the stage of reading the build parameters.
Comments: Itai Ganot
Tags: <jenkins><jenkins-pipeline><jenkinsfile><jenkins2>
Title: Jenkins parameters default to env variable?
UserDisplayName: rp346
ThreadText: # 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}`  
  
  ---
  
  