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.

variable value not changing in groovy script #3827

kcnu1 ·

I am using below Groovy script to check existence of files and changing the variable from false to true, but noticed that it's still printing as false even after setting it with vars.get("myTestVar").setValue() method. Am I missing anything?

The variable is used another step in the same configuration and it's not getting triggered since 'myTestVar' is always false, irrespective of the code below.

We are on Quickbuild version 6.1.9.

groovy:
import static groovy.io.FileType.FILES;
import com.pmease.quickbuild.Context;

Context.getLogger().info("myTestVar value:" + "${vars.getValue("myTestVar")}");	
new File('/opt/myData/abc').eachFileRecurse(FILES) {
    if(it.name.startsWith('XYZ')) {
        vars.get("myTestVar").setValue(true);
        Context.getLogger().info("myTestVar again:" + "${vars.getValue("myTestVar")}");
    } else {
        vars.get("myTestVar").setValue(false);
    }
}
  • replies 10
  • views 4113
  • stars 0
robinshen ADMIN ·

Value of changes variable can only been seen by steps logically after th step changing the variable. For instance steps executing corruently with current step will not see the change.

kcnu1 ·

Sorry, I didn't make it clear. The above script is in step 1, and I am checking the variable value in step 2 and 3 of the same configuration. Shouldn't it return it as true in step 2 & 3 checks?

To be specific, I am using Execute condition with a 'if specified variable evaluate to true' approach in steps 2 and 3.
Is there a different approach that would work here?

Thanks

kcnu1 ·

Hello Robin, would you please see above message and let me know update?

Thanks

robinshen ADMIN ·

I did the test and it works at my side. My set up is to add two steps into a sequential composition step, and the first step changes value of a variable, and the second step's condition uses that variable. Is step 2&3 under the same SEQUENTIAL (not PARALLEL) container as step1?

kcnu1 ·

That's strange since our setup is not working. All 3 steps are part of the same sequential composition, so not sure why it would not work.
Should I print anything to debug this further?

Added a dummy step to print the variable value between 1 & 2 and noticed that the variable value is not getting updated when changed in the script. Is there another API to update the composition variable value between steps?

Thanks

robinshen ADMIN ·

Can you please reproduce this issue in a sample database and send me [robin AT pmease DOT com] the backup for diagnostics?

kcnu1 ·

Robin,

I add 2nd parameter 'false' to setValue() call and now I get correct value in step 2 & 3 which are sequential.
Not sure if this is a known behavior or some issue with our QB version.

groovy:
import static groovy.io.FileType.FILES;
import com.pmease.quickbuild.Context;

Context.getLogger().info("myTestVar value:" + "${vars.getValue("myTestVar")}"); 
new File('/opt/myData/abc').eachFileRecurse(FILES) {
  if(it.name.startsWith('XYZ')) {
    vars.get("myTestVar").setValue(true, false);
    Context.getLogger().info("myTestVar again:" + "${vars.getValue("myTestVar")}");
  } else {
    vars.get("myTestVar").setValue(false, false);
  }
}
robinshen ADMIN ·

Even with second param as true, it works at my side. If you can reproduce the issue with a sample database, it will help us to identify the issue quickly.

kcnu1 ·

Were you referring to 'maintenance' as sample database or something else?
Let me know details and I will copy the configuration there and reproduce the issue.

robinshen ADMIN ·

I meant to set up a brand new QB instance and reproduce your issues there. And then backup the database to send.