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.

automatically overwrite variables for child configurations when creating them #4009

OnQuickBuild ·

Hello Robin

I now have a template configuration that defines all the build steps. They don't change basically, and the child configurations can just run build with minimal changes, such as (repo).

But child configurations will inherit the variables, then I have to manually overwrite them all so that the child configurations won't share the same variables from parent config.
I do this by clicking on the variable edit icon, then press enter.

I wonder if there's an automatic way to do this?

Thank you!

  • replies 3
  • views 45
  • stars 0
robinshen ADMIN ·

You may create the child configuration and override variables via script. The idea is:

  1. Create a separate configuration say "root/creation"
  2. Add a step running below script:
groovy:
import com.pmease.quickbuild.model.Configuration;
import com.pmease.quickbuild.variable.Variable;
def parentConf = system.configurationManager.get("path/to/parent-conf");
def newChildConf = new Configuration();
newChildConf.setName(vars.getValue("childConfName"));
newChildConf.setParent(parentConf);
def overrideVar1 = new Variable();
overrideVar1.setName("var1");
overrideVar1.setValue(vars.getValue("var1"));
newChildConf.variables.add(overrideVar1);
system.configurationManager.save(newChildConf);
  1. Define variable "childConfName" and "var1" in "root/creation" and specify appropriate prompt setting
  2. Now if you want to create new child configuration, just run "root/creation" with appropriate options. This example only overrides "var1", you may certainly override other variables if necessary.
OnQuickBuild ·

I suppose when you set newChildConf.setParent(parentConf);
the child config will automatically inherit the parentConf (which is my "template config") steps?

I don't need to override the variables to a certain value. Because the build steps will do that. I just need to override it so that multiple child configs won't override each other's variable values, since they all inherit the parent config's variables.

But how do you control the number of variables? It can't be hardcoded.
Maybe there's a function to retrieve all variables of "template config", then according to the variable names I can set the value to a random value, maybe just '' or null.
But does this "override" the variable itself like clicking on the override icon manually, which breaks the connection with template config's variable values?

Thanks

robinshen ADMIN ·

You may get all variables defined in template conf:
groovy:
for (var in parentConf.getVariables()) {
// do something with var.name, var.value, etc.
}