Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Getting value of a variable from a build #3233

stephasaurus ·
Hi - We are having an issue I hope you can help us with. For reference, we are using QB 6.0.16

We have a variable in configurationA called myVar. In the configurationA's variables, myVar is set as a groovy script, so ${groovy:....} which is evaluated when the build runs. So when we run buildX in configuration A, in the buildX, myVar is set to 12345. When we look at the buildX's variables tab (on the left side column under "Overview"), myVar also shows "12345." This is as we expect.

However, if, from configuration B, we call configurationA.getLatestBuild().getVarValue('myVar'), it evaluates configurationA's ${groovy:...} script of myVar instead of giving us the 12345 value from buildX that we are expecting.

We did not have this problem when using QB 6.0.4 (we went from 6.0.4 -> 6.0.16), so can you please tell me if this is a bug in the evaluation or why this has changed? Otherwise, how are we able to get the 12345 value?

Thank you!
  • replies 3
  • views 2843
  • stars 0
robinshen ADMIN ·
This works at my side with 6.0.16. What I am doing:
1. add root/confA, and define a variable "varA" inside it with value ${groovy: new Date().toString()}
2. add a step in root/confA to print this variable: echo ${vars.getValue("varA")}
3. run root/confA and write down value of varA in the latest build
4. now add another configuration root/confB, with a step running below script:
groovy:
logger.info(system.getConfiguration("root/confA").getLatestBuild().getVarValue("varA"));

The value printed when running root/confB is exactly the same as the value recorded in latest build of confA.
stephasaurus ·
OK, here's a bit more of what we're actually doing, which is more complex than the initial example:

1. Add root/configA
2. Add root/configA/configB
3. Add variable to root/configA called "time" and value is the following: ${groovy: new Date().toString()}
4. Add step to root/configA to print "time", echo ${vars.getValue('time')}
5. Run root/configA
6. Change root/configA's time var to the following:
${groovy: String time = system.getConfiguration('root/configA').getLatestSuccessfulBuild().getVarValue('time'); time}
4. Add step to root/configA/configB to print time var (inherited from root/configA), using "echo ${vars.getValue('time')}
5. Run root/configA/configB

This should fail with a "Found circular reference of variable: time" error. However, if I run this exact same procedure on 6.0.4, we do not get this error. Was the circular reference detection upped between these releases? This situation isn't ideal and is a circular reference, we just did not anticipate needing to fix this at this time since it worked in 6.0.4.

Thanks!
robinshen ADMIN ·
Yes we have made the change after 6.0.4 to detect circular references such as this. It is not normal use of variable to have it uses value of itself recorded in build.