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.

override variable with groovy script #3497

happymmm ·
i have a variable defined in root level, say xyz. a child configuration, A, obviously has an inherited variable of "xzy". In a different child configuration, B, I would like to use groovy script to override "xyz" value in configuration "A". i keep getting an error of "java.lang.NullPointerException: Cannot invoke method setValue() on null object".

def conf = system.getConfiguration('root/A');
conf.getVar("xyz").setValue("123");


if i use "conf.variables.add(var);", it works. however, it would keep adding a new variable for each build.
  • replies 1
  • views 2713
  • stars 0
robinshen ADMIN ·
Please try below script:

def conf = system.getConfiguration('root/A');
def var = null;
for (each in conf.variables) {
if (each.name == "xyz") {
var = each;
break;
}
}
if (var == null) { // var "xyz" not defined in "root/A", so we add a new one (this effectively overrides the one defined in "root")
var = new com.pmease.quickbuild.variable.Variable();
var.setName("xyz");
var.setValue("123");
conf.variables.add(var);
} else { // the variable already defined in "root/A", so we simply change the value
var.setValue("123");
}
system.configurationManager.save(conf); // do not forget to save the configuratioin