2

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 Aug 2 '18 at 9:29
  • @Ilhicas it was a typo – David West Aug 2 '18 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 Aug 2 '18 at 14:31
  • @Ilhicas it is globally declared. – David West Aug 2 '18 at 17:52
4

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

Thanks all for your answers.

3

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 Aug 17 '18 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. – Jiri Klouda Aug 17 '18 at 19:04
  • I used def suiteRunId at the top of the pipeline and now the pipeline is functioning. – David West Aug 17 '18 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. – Jiri Klouda Aug 17 '18 at 21:01
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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