Answers: <p>The block needs to be resolved for each stage, otherwise you could not use stage dependent methods in the block, so there would need to be some check on what methods to use and what to not use, it would lead to even more problems. Further each stage can be executed on different node, so the code needs to re-resolve it. Otherwise it would just behave differently with single node or in parallel. Just deal with it.</p>
  
  <p>Instead of setting the variables in the environment block, simply set them in the first stage. And in the agent set the <code>reuseNode true</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-08-17T17:25:27.957Z
Answers: It is using the same node.Even with the added missing quote it gets a different UUID.
Answers: David West
Answers: CC BY-SA 4.0
Answers: 2018-08-17T19:04:41.403Z
Answers: Did you add a stage in which you would set the variables? Don't set them in the environment block, set them in the first stage block.
Answers: Jiri Klouda
Answers: CC BY-SA 4.0
Answers: 2018-08-17T19:07:15.243Z
Answers: I used `def suiteRunId` at the top of the pipeline and now the pipeline is functioning.
Answers: David West
Answers: CC BY-SA 4.0
Answers: 2018-08-17T21:01:01.800Z
Answers: If you have a different solution, make sure to write up an answer, David. It is perfectly good thing to answer your own question.
Answers: Jiri Klouda
Answers: CC BY-SA 4.0
Answers: 2018-08-04T21:13:39.267Z
Answers: 2018-08-04T21:13:39.267Z
Answers: Jiri Klouda
Answers: <p>If only you would add the missing quote for SMOKE_CMD (credits to <a href="https://devops.stackexchange.com/users/8534/ilhicas">ilhicas</a> who first mentioned something about that in a comment below your question), you might get UUIDs that are no longer different ... Similar to what you seem to have done in revision 2 of your question already.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-08-04T08:31:44.797Z
Answers: 2018-08-04T08:31:44.797Z
Answers: Pierre.Vriens
Answers: <p><code>def suiteRunId = UUID.randomUUID().toString()</code> worked at the top of the <code>Jenkinsfile</code>.</p>
  
  <p>Thanks all for your answers.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-08-20T12:59:56.080Z
Answers: 2018-08-20T12:59:56.080Z
Answers: David West
Body: <p>I have an environment block</p>
  
  <pre><code>environment {
    SUITE_RUN_ID = UUID.randomUUID().toString()
    SMOKE_CMD = "runtests.sh SUITE_RUN_ID=${SUITE_RUN_ID}" 
    FAILED_TESTS = "output_rerun_info.rb SUITE_RUN_ID=${SUITE_RUN_ID}"
  }
  </code></pre>
  
  <p>When I use SMOKE_CMD and FAILED_TESTS in their respective stages I get different UUIDs... why?</p>
  
Comments: CC BY-SA 4.0
Comments: 2018-08-02T09:29:29.227Z
Comments: Is it a typo or are you actually missing the end quotes under the SMOKE_CMD ?
Comments: Ilhicas
Comments: CC BY-SA 4.0
Comments: 2018-08-02T13:58:13.840Z
Comments: @Ilhicas it was a typo
Comments: David West
Comments: CC BY-SA 4.0
Comments: 2018-08-02T14:31:26.350Z
Comments: can you provide the location of the environment definition? Is it globally declared or under each stage? https://jenkins.io/doc/pipeline/tour/environment/
Comments: Ilhicas
Comments: CC BY-SA 4.0
Comments: 2018-08-02T17:52:08.123Z
Comments: @Ilhicas it is globally declared.
Comments: David West
Tags: <jenkins-pipeline><groovy>
Title: Jenkins UUIDs ... oh the humanity
UserDisplayName: David West
ThreadText: # Jenkins UUIDs ... oh the humanity
  
  (Asked by: username_0 on 2018-08-01)
  
  I have an environment block
  
  ```
  environment {
    SUITE_RUN_ID = UUID.randomUUID().toString()
    SMOKE_CMD = "runtests.sh SUITE_RUN_ID=${SUITE_RUN_ID}" 
    FAILED_TESTS = "output_rerun_info.rb SUITE_RUN_ID=${SUITE_RUN_ID}"
  }
  
  ```
  
  When I use SMOKE\_CMD and FAILED\_TESTS in their respective stages I get different UUIDs... why?
  
  **Tags:** jenkins-pipeline, groovy
  
  > **Comments:**
  > **username_1**: Is it a typo or are you actually missing the end quotes under the SMOKE_CMD ?  
  > **username_0**: @username_1 it was a typo  
  > **username_1**: can you provide the location of the environment definition? Is it globally declared or under each stage? https://jenkins.io/doc/pipeline/tour/environment/  
  > **username_0**: @username_1 it is globally declared.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2018-08-20. Score: 6 | Accepted answer
  
  `def suiteRunId = UUID.randomUUID().toString()` worked at the top of the `Jenkinsfile`.
  
  Thanks all for your answers.
  
  
  ---
  
  ### Answer by username_2 on 2018-08-04. Score: 4
  
  The block needs to be resolved for each stage, otherwise you could not use stage dependent methods in the block, so there would need to be some check on what methods to use and what to not use, it would lead to even more problems. Further each stage can be executed on different node, so the code needs to re-resolve it. Otherwise it would just behave differently with single node or in parallel. Just deal with it.
  
  Instead of setting the variables in the environment block, simply set them in the first stage. And in the agent set the `reuseNode true`.
  
  > **Comments:**
  > **username_0**: It is using the same node.Even with the added missing quote it gets a different UUID.  
  > **username_2**: Did you add a stage in which you would set the variables? Don't set them in the environment block, set them in the first stage block.  
  > **username_0**: I used `def suiteRunId` at the top of the pipeline and now the pipeline is functioning.  
  > **username_2**: If you have a different solution, make sure to write up an answer, username_0. It is perfectly good thing to answer your own question.  
  
  ---
  
  ### Answer by username_3 on 2018-08-04. Score: 0
  
  If only you would add the missing quote for SMOKE\_CMD (credits to [username_1](https://devops.stackexchange.com/users/8534/username_1) who first mentioned something about that in a comment below your question), you might get UUIDs that are no longer different ... Similar to what you seem to have done in revision 2 of your question already.
  
  
  ---
  
  