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?

  • Is it a typo or are you actually missing the end quotes under the SMOKE_CMD ?
    – Ilhicas
    Commented Aug 2, 2018 at 9:29
  • @Ilhicas it was a typo
    – David West
    Commented Aug 2, 2018 at 13:58
  • can you provide the location of the environment definition? Is it globally declared or under each stage? jenkins.io/doc/pipeline/tour/environment
    – Ilhicas
    Commented Aug 2, 2018 at 14:31
  • @Ilhicas it is globally declared.
    – David West
    Commented Aug 2, 2018 at 17:52

3 Answers 3


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

Thanks all for your answers.


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.

  • It is using the same node.Even with the added missing quote it gets a different UUID.
    – David West
    Commented Aug 17, 2018 at 17:25
  • 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. Commented Aug 17, 2018 at 19:04
  • I used def suiteRunId at the top of the pipeline and now the pipeline is functioning.
    – David West
    Commented Aug 17, 2018 at 19:07
  • If you have a different solution, make sure to write up an answer, David. It is perfectly good thing to answer your own question. Commented Aug 17, 2018 at 21:01

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.