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.

variables from source control #4529

drdt ·

My build has a variable which is actually a script to extract a setting from pom.xml in the source code repo (Perforce). I access this at the beginning of the build (when setting build.version), but also reference it many times later in the build.

srcProductVersion = (<version> tag from pom.xml)
srcBuildNumber = incrementing counter
build.version = srcProductVersion-srcBuildNumber

I recently discovered that if I access srcProductVersion from a step running on a node where the Perforce client is not installed, an error is generated and the variable comes back undefined. This is a problem; in addition to failing my build and invalidating my method, we seem to be putting undue load on the Perforce server. It implies to me that we are accessing Perforce every time I access this variable, or any of the variables that reference it. I think I had been in the impression that we would read the file once and then use the cached value after that.

Can someone shed some light on this mechanism, and what I can do to work around this issue? We have recently started implementing a new capability that also uses this method.

  • replies 5
  • views 825
  • stars 1
robinshen ADMIN ·

If you are using a script for value of a variable, the script logic will be executed every time the variable is accessed. You may however implement the cache logic in your script:

groovy:
if (request.variables.containsKey("cacheVar"))
  return request.variables["cacheVar"];
else {
  // your logic to calculate myVarValue
  request.variables["cacheVar"] = myVarValue;
}

Note here "cacheVar" should not be defined in variables tab.

drdt ·

Brilliant!

But what is this 'request.variables", is it new to the API?

robinshen ADMIN ·

It is there from day 1, and used to carry variables specified when run build manually, but can be used for this purpose.

drdt ·

We have been using this syntax to create variables during the build:

varWrapper = new VariableWrapper( var, value );
varWrapper.setSnapshot( value );
Context.get().getVariables().put( var, varWrapper );

Is the request.variables method better?

robinshen ADMIN ·

Yes, request.variables is simpler.