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.

Create/Override/Modify variables in a configuration #3527

robinshen ADMIN ·
Sometimes, you may want to create new variable or override existing variable in a configuration. Below groovy script can do the job:
import com.pmease.quickbuild.variable.Variable;
import com.pmease.quickbuild.variable.PromptSetting;

def confToModify = system.getConfiguration("root/path/to/conf");
def varName = "name of interesting variable";
def interestingVar = null;
for (var in confToModify.getVariables()) {
if (var.getName() == varName) {
interestingVar = var;
if (interestingVar == null) {
interestingVar = new Variable();
interestingVar.setValue("var value");
interestingVar.setPromptSetting(new PromptAsTextInput());
} else {
interestingVar.setValue("var value");
interestingVar.setPromptSetting(new PromptAsTextInput());
  • replies 1
  • views 2978
  • stars 0
mobusdorphin ·

I've spent about an hour trying to get this to work. I was loading the configuration, getting the variable, then setting the value, but the variable was never changing, even though logging the value of it after the change showed the new value. This would work fine if I was changing a variable that belonged to the configuration that was running, but I could not get the change to stick on a different configuration than what I was running.

The important step to get this to persist after the build finishes is the; which I passed over a bit because it was at the very bottom. I am supposing that this automatically runs at the end of every build, but since I was modifying a different configuration, that save() method didn't affect the modified configuration.

Just in case anyone is googling this like I was today and is stuck where I was.