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.

Cache script output #3856

xjjx ·

Hello,

I have configuration with about ten variables which contains same script ( as below ). It simply allow to choose builds from other configurations. This takes some time on start of build ( about 2 min ). I tried to add this script to only one variable for cache purpose and then use value of this "cache" in other variables, but it seems that it copy script end execute 10 times.
So, is there any way to create some variable (in my script is "output") on the fly during start of configuration and then later use this value in variables ?

${ groovy:
def output = []
def arr = []
def conf = system.getConfiguration("root/SomeConfWithSubConfigurations")
system.configurationManager.getChildren(conf).each {
arr.push(it.pathName)
}

arr.each {
logger.info(it)
system.getBuildManager().getBuilds(system.getConfiguration(it)).each {
if(it.getStatus().toString() == "SUCCESSFUL") {
output << (it.getConfiguration().getPathName() + ":" +it.getVersion())
}
}
}

util.join(output)
}

  • replies 5
  • views 851
  • stars 0
robinshen ADMIN ·

Variable expressions will always be evaluated upon access. You may define a variable say "output", and in pre-queue script of the configuration (advanced setting of the configuration), do the following:

def output = []
def arr = []
def conf = system.getConfiguration("root/SomeConfWithSubConfigurations")
system.configurationManager.getChildren(conf).each {
arr.push(it.pathName)
}

arr.each {
logger.info(it)
system.getBuildManager().getBuilds(system.getConfiguration(it)).each {
if(it.getStatus().toString() == "SUCCESSFUL") {
output << (it.getConfiguration().getPathName() + ":" +it.getVersion())
}
}
}

vars.get("output").setValue(util.join(output), false);

Then whenever you access the output variable later, the value will be right there.

xjjx ·

This solution doesn't seem to work in our case.
We have multiple variables that are configured like below:

Name:				A
	Prompt Settings: 	prompt as selection box
	Display Name:		For A choose build:
	Choices: 			${vars.getValue("output")}
	
	Name:				B
	Prompt Settings: 	prompt as selection box
	Display Name:		For B choose build:
	Choices: 			${vars.getValue("output")}
	
	and some more

What we would like to have is set of prompts to user at build start.
User should choose from the build list for each prompt and each prompt should propose same list of choices.
It cause the issue at the moment due to the fact that prompt data is generated before pre-queue script I suppose.
Due to that we have some latency between starting the build and appearing "Specify Build Options" screen.

robinshen ADMIN ·

I see. Please define a variable say "outputCache" with value left blank, and rewrite the output variable value as below:

${ groovy:
String cachedOutput = vars.getValue("outputCache");
if (cachedOutput == null) {
// your normal logic to calculate output
vars.get("outputCache").setValue(cachedOutput, false);
}
return cachedOutput;
}

Note that '}' should be escaped as '}' in embedded script.

xjjx ·

Thanks for all help. It works for us only when second parameter to setValue is set to "true", but in this case it's leave garbage in outputCache variable. Anyway it turned out that there is almost no significant performance change, so probably there is some caching already - maybe on database level. I have one small improvement idea: it would be nice to have Pre-VariablePromptScreen script (or how you name this place where you choose variable values) field in Advanced Settings.

robinshen ADMIN ·

You may submit an improvement request for this at track.pmease.com