4

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?

David West
  • 1,533
  • 3
  • 18
  • 25

3 Answers3

6

def suiteRunId = UUID.randomUUID().toString() worked at the top of the Jenkinsfile.

Thanks all for your answers.

David West
  • 1,533
  • 3
  • 18
  • 25
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.

Jiri Klouda
  • 5,867
  • 1
  • 22
  • 54
0

If only you would add the missing quote for SMOKE_CMD (credits to 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.

Pierre.Vriens
  • 7,225
  • 14
  • 39
  • 84