Skip to content

Commit 4163d5c

Browse files
committed
Honor skipProgressUpdates for queued and checkout status publishes
The skipProgressUpdates property only guarded the stage updates published by ChecksGraphListener. The "queued" status published when a job is scheduled and the "in progress" statuses published after every SCM checkout ignored the flag, so a job opting out of progress updates still published several intermediate statuses per build. With the flag set, the final completed status is now the only publish.
1 parent 9397079 commit 4163d5c

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

src/main/java/io/jenkins/plugins/checks/status/AbstractStatusChecksProperties.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public boolean isSuppressLogs(final Job<?, ?> job) {
6464
}
6565

6666
/**
67-
* Returns whether to suppress progress updates from the {@link io.jenkins.plugins.checks.status.FlowExecutionAnalyzer}.
68-
* Queued, Checkout and Completed will still run but not 'onNewHead'
67+
* Returns whether to suppress intermediate progress updates: the "queued" status published when the job is
68+
* scheduled, the "in progress" status published after each SCM checkout, and the stage updates from the
69+
* {@link io.jenkins.plugins.checks.status.FlowExecutionAnalyzer}. The final completed status is always published.
6970
*
7071
* @param job
7172
* A jenkins job.

src/main/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisher.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static class JobScheduledListener extends QueueListener {
137137
* {@inheritDoc}
138138
*
139139
* <p>
140-
* When a job enters queue, creates the check on "queued".
140+
* When a job enters queue, creates the check on "queued", unless progress updates are skipped.
141141
* </p>
142142
*/
143143
@Override
@@ -147,6 +147,10 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
147147
}
148148

149149
final Job<?, ?> job = (Job<?, ?>) wi.task;
150+
if (findProperties(job).isSkipProgressUpdates(job)) {
151+
return;
152+
}
153+
150154
getChecksName(job).ifPresent(checksName -> runAsync(() -> {
151155
ChecksPublisher publisher = ChecksPublisherFactory.fromJob(job, TaskListener.NULL);
152156
publish(publisher, ChecksStatus.QUEUED, ChecksConclusion.NONE, checksName, null);
@@ -169,13 +173,18 @@ public static class JobCheckoutListener extends SCMListener {
169173
* {@inheritDoc}
170174
*
171175
* <p>
172-
* When checkout finished, update the check to "in progress".
176+
* When checkout finished, update the check to "in progress", unless progress updates are skipped.
173177
* </p>
174178
*/
175179
@Override
176180
public void onCheckout(final Run<?, ?> run, final SCM scm, final FilePath workspace,
177181
final TaskListener listener, @CheckForNull final File changelogFile,
178182
@CheckForNull final SCMRevisionState pollingBaseline) {
183+
Job<?, ?> job = run.getParent();
184+
if (findProperties(job).isSkipProgressUpdates(job)) {
185+
return;
186+
}
187+
179188
getChecksName(run).ifPresent(checksName -> publish(ChecksPublisherFactory.fromRun(run, listener),
180189
ChecksStatus.IN_PROGRESS, ChecksConclusion.NONE, checksName, null));
181190
}

src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,29 @@ public void shouldPublishStatusWithProperties() throws Exception {
149149
assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.SUCCESS);
150150
}
151151

152+
/**
153+
* Tests that when progress updates are skipped, the only published status is the final completed one:
154+
* nothing is published when the job is scheduled or when checkout finishes.
155+
*/
156+
@Test
157+
public void shouldOnlyPublishCompletedStatusWhenProgressUpdatesAreSkipped() throws Exception {
158+
getProperties().setApplicable(true);
159+
getProperties().setSkipped(false);
160+
getProperties().setSkipProgressUpdates(true);
161+
getProperties().setName("Test Status");
162+
163+
buildSuccessfully(createFreeStyleProject());
164+
// Wait for the job to finish to work around slow Windows builds sometimes
165+
this.getJenkins().waitUntilNoActivity();
166+
assertThat(getFactory().getPublishedChecks()).hasSize(1);
167+
168+
ChecksDetails details = getFactory().getPublishedChecks().get(0);
169+
170+
assertThat(details.getName()).contains("Test Status");
171+
assertThat(details.getStatus()).isEqualTo(ChecksStatus.COMPLETED);
172+
assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.SUCCESS);
173+
}
174+
152175
/**
153176
* Test checks output includes pipeline details.
154177
*/
@@ -556,6 +579,7 @@ static class ChecksProperties extends AbstractStatusChecksProperties {
556579
private boolean skipped;
557580
private String name;
558581
private boolean suppressLogs;
582+
private boolean skipProgressUpdates;
559583

560584
public void setApplicable(final boolean applicable) {
561585
this.applicable = applicable;
@@ -573,6 +597,10 @@ public void setSuppressLogs(final boolean suppressLogs) {
573597
this.suppressLogs = suppressLogs;
574598
}
575599

600+
public void setSkipProgressUpdates(final boolean skipProgressUpdates) {
601+
this.skipProgressUpdates = skipProgressUpdates;
602+
}
603+
576604
@Override
577605
public boolean isApplicable(final Job<?, ?> job) {
578606
return applicable;
@@ -592,5 +620,10 @@ public boolean isSkipped(final Job<?, ?> job) {
592620
public boolean isSuppressLogs(final Job<?, ?> job) {
593621
return suppressLogs;
594622
}
623+
624+
@Override
625+
public boolean isSkipProgressUpdates(final Job<?, ?> job) {
626+
return skipProgressUpdates;
627+
}
595628
}
596629
}

0 commit comments

Comments
 (0)