i was wondering if there is an easy solution to rerun a build that isn't typically run (i.e. a triggered build). In this case, I only want to rerun one triggered build from a larger build which contained several triggers, but I want it to just rerun it with all the same variable values it had in the previous run without having to define them as prompted. Is this possible?
QB only runs a build once in a trigger chain for the same set of input variables. So work around this, you may define a psuedo variable say "timestamp", and pass the value ${new Date()} so that the variable input differs from previous run.
I'm not entirely sure what trigger chain means in this scenario, but I think this is a slightly different situation. Here's what I want to accomplish:
Build A triggers Build B as part of its build.
Build B fails, and subsequently Build A fails because it waits for the results of Build B.
After Build A has completed, I only want to rerun Build B and not Build A, but I want to run Build B with the same parameters as the run that was triggered by Build A.
I was looking for an easy way to get all the parameters that were part of Build B into another run of Build B, but without utilizing the trigger in Build A. Essentially just "rerun Build B with these same parameters".
I see. You may define a variable say "usePrevVariables" in Conf A, and set its default value to false. This variable should be prompted, and pre-queue script of Conf A can be specified as below to take previous variable values if "usePrevVariables" is ticked when manually triggers Conf A:
groovy:
if (vars.get("usePrevVariables").asBoolean() && configuration.latestFinishedBuild != null) {
request.getVariables().clear();
request.getVariables().putAll(configuration.latestFinishedBuild.getVariableValues());
}
Suggested approach above is incorrect as build variable populating happens before pre-queue script is running. Please clear the pre-queue script, and use below for pre-build script:
groovy:
import com.pmease.quickbuild.variable.*;
if (request.promotionSource) {
buildId = request.promotionSource.buildId
if (buildId) {
prevBuild = system.buildManager.load(request.promotionSource.buildId);
for (Map.Entry<String, String> entry: prevBuild.variableValues.entrySet()) {
var = new VariableWrapper(entry.getKey(), entry.getValue());
varDef = configuration.findVar(var.getName());
if (varDef != null && (varDef.getValueProvider() instanceof SecretValueProvider || varDef.getPromptSetting() instanceof PromptAsPasswordInput)) {
var.setSecret(true);
}
var.setSnapshot(entry.getValue());
build.getVariables().put(entry.getKey(), var);
}
}
}