<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>

CC BY-SA 4.0
2018-08-17T17:25:27.957Z
It is using the same node.Even with the added missing quote it gets a different UUID.
David West
CC BY-SA 4.0
2018-08-17T19:04:41.403Z
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.
Jiri Klouda
CC BY-SA 4.0
2018-08-17T19:07:15.243Z
I used `def suiteRunId` at the top of the pipeline and now the pipeline is functioning.
David West
CC BY-SA 4.0
2018-08-17T21:01:01.800Z
If you have a different solution, make sure to write up an answer, David. It is perfectly good thing to answer your own question.
Jiri Klouda
CC BY-SA 4.0
2018-08-04T21:13:39.267Z
2018-08-04T21:13:39.267Z
Jiri Klouda
<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>

CC BY-SA 4.0
2018-08-04T08:31:44.797Z
2018-08-04T08:31:44.797Z
Pierre.Vriens
<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>

CC BY-SA 4.0
2018-08-20T12:59:56.080Z
2018-08-20T12:59:56.080Z
David West
<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>

CC BY-SA 4.0
2018-08-02T09:29:29.227Z
Is it a typo or are you actually missing the end quotes under the SMOKE_CMD ?
Ilhicas
CC BY-SA 4.0
2018-08-02T13:58:13.840Z
@Ilhicas it was a typo
David West
CC BY-SA 4.0
2018-08-02T14:31:26.350Z
can you provide the location of the environment definition? Is it globally declared or under each stage? https://jenkins.io/doc/pipeline/tour/environment/
Ilhicas
CC BY-SA 4.0
2018-08-02T17:52:08.123Z
@Ilhicas it is globally declared.
David West
<jenkins-pipeline><groovy>
Jenkins UUIDs ... oh the humanity
David West
# 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, David. 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 [ilhicas](https://devops.stackexchange.com/users/8534/ilhicas) 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.


---

