Skip to content

Commit

Permalink
Merge pull request #558 from jenkinsci/overwrite-action
Browse files Browse the repository at this point in the history
[JENKINS-73380] Make sure that any existing reference build action is removed
  • Loading branch information
uhafner authored Sep 19, 2024
2 parents 99e2c70 + 444a93f commit 29da418
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public void perform(@NonNull final Run<?, ?> run, @NonNull final FilePath worksp
@NonNull final Launcher launcher, @NonNull final TaskListener listener) {
FilteredLog log = new FilteredLog("Errors while computing the reference build:");

var existing = run.removeActions(ReferenceBuild.class);
if (existing) {
log.logError("Replaced existing reference build, this typically indicates a misconfiguration "
+ "as the reference should be constant");
}
run.addAction(findReferenceBuild(run, log));

LogHandler logHandler = new LogHandler(listener, "ReferenceFinder");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ void shouldSkipFailedBuildsIfResultIsWorseThanRequired(final String requiredResu
StringUtils.defaultIfBlank(requiredResult, "UNSTABLE")));
}

@Test
@Issue("JENKINS-73380")
void shouldOverwriteReferenceBuild() {
WorkflowJob reference = createPipeline();
reference.setDefinition(new CpsFlowDefinition(
"node {\n"
+ "echo 'Hello Job'\n"
+ " }\n", true));
Run<?, ?> baseline = buildWithResult(reference, Result.SUCCESS);

var job = createPipeline();
var script = "node {\n"
+ discoverReferenceJob(reference.getName())
+ discoverReferenceJob(reference.getName())
+ " }\n";
job.setDefinition(new CpsFlowDefinition(script, true));

Run<?, ?> current = buildSuccessfully(job);

assertThat(findReferenceBuild(current)).contains(baseline);
assertThat(getConsoleLog(current)).contains(
"[-ERROR-] Replaced existing reference build, this typically indicates a misconfiguration as the reference should be constant");
}

private String discoverReferenceJob(final String referenceJobName, final String... arguments) {
var joiner = new StringJoiner(", ", ", ", "").setEmptyValue("");
Arrays.stream(arguments).forEach(joiner::add);
Expand Down

0 comments on commit 29da418

Please sign in to comment.