groovy:
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;
break;
}
}
if (interestingVar == null) {
interestingVar = new Variable();
interestingVar.setName(varName);
interestingVar.setValue("var value");
interestingVar.setPromptSetting(new PromptAsTextInput());
confToModify.getVariables().add(var);
} else {
interestingVar.setName(varName);
interestingVar.setValue("var value");
interestingVar.setPromptSetting(new PromptAsTextInput());
}
system.configurationManager.save(confToModify);
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 system.configurationManager.save(confToModify); 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.