Our review system trigger some tests on a QB configuration through rest API and I do not want each test to be triggered as separate build. All tests belonging to same review should be triggered in the same build. The standard API provided by review system can send rest api requests test-wise only.
I have been trying to merge requests from the same review in a single build as they have some common task to be performed.
Let's say for review id '1234' , three test builds are requested ,say, Build A, build B , build C ( could be in any order)
I have a variable USEFUL_VAR in each request which I want to merge in single build. If Build A is served first, I would like to append values of variable USEFUL_VAR of BUILD requests B and C into Build A.
But every time I try this I have been facing all sorts of concurrency issues in QB. Sometimes I lose some variables in the variable map and other times build C starts running which would be expected to be cancelled.
...
// IF a RUNNING build and Current request have same REVIEW id ( say , 1234)
// b_id is the build id of the FIRST Test (say, BUILD A ) with same review id
def b_id = BuildEngine.instance.getBuildId(it.getId(),null);
if(b_id != null )
{
try{
String varName="USEFUL_VAR",varValue = request.getVariables().get("USEFUL_VAR")
Build b = system.buildManager.load(b_id)
Map<String, VariableWrapper> variables = b.getVariables()
varValue = b.getVarValue(varName) + "\n" + varValue
variables.put(varName, new VariableWrapper(varName, varValue))
b.getVariables().get(varName).setValue(varValue)
system.buildManager.saveVariables(b_id, variables.values())
}
catch(e){
logger.error("ERROR-updateVariable(varName=" + varName + " / varValue=" + varValue + "): " + e.getMessage())
}
}
// Cancel the current build request now as we have appended the important variable value
...
Could you please suggest a solution for how I can achieve this target of merging same name variables of different build requests?