Skip to content

Commit 9f09a0c

Browse files
authored
Merge pull request jenkinsci#62 from jglick/exitStatus-JENKINS-48300
[JENKINS-48300] Call new API to get messages about negative exit codes
2 parents c600735 + 6d4b826 commit 9f09a0c

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<parent>
2929
<groupId>org.jenkins-ci.plugins</groupId>
3030
<artifactId>plugin</artifactId>
31-
<version>3.0</version>
31+
<version>3.2</version>
3232
<relativePath />
3333
</parent>
3434
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -75,7 +75,7 @@
7575
<dependency>
7676
<groupId>org.jenkins-ci.plugins</groupId>
7777
<artifactId>durable-task</artifactId>
78-
<version>1.16</version>
78+
<version>1.18-20180125.194359-1</version> <!-- TODO https://github.com/jenkinsci/durable-task-plugin/pull/57 -->
7979
</dependency>
8080
<dependency>
8181
<groupId>org.jenkins-ci.plugins.workflow</groupId>

src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import hudson.util.LogTaskListener;
3737
import hudson.util.NamingThreadFactory;
3838
import java.io.IOException;
39-
import java.io.PrintStream;
4039
import java.nio.charset.Charset;
4140
import java.util.Set;
4241
import java.util.concurrent.ScheduledFuture;
@@ -196,7 +195,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
196195
LOGGER.log(Level.FINE, node + " is evidently offline now", x);
197196
ws = null;
198197
if (!printedCannotContactMessage) {
199-
logger().println("Cannot contact " + node + ": " + x);
198+
listener().getLogger().println("Cannot contact " + node + ": " + x);
200199
printedCannotContactMessage = true;
201200
}
202201
return null;
@@ -207,7 +206,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
207206
return ws;
208207
}
209208

210-
private @Nonnull PrintStream logger() {
209+
private @Nonnull TaskListener listener() {
211210
TaskListener l;
212211
StepContext context = getContext();
213212
try {
@@ -223,7 +222,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
223222
l = new LogTaskListener(LOGGER, Level.FINE);
224223
recurrencePeriod = 0;
225224
}
226-
return l.getLogger();
225+
return l;
227226
}
228227

229228
private @Nonnull Launcher launcher() throws IOException, InterruptedException {
@@ -238,21 +237,21 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
238237
@Override public void stop(final Throwable cause) throws Exception {
239238
FilePath workspace = getWorkspace();
240239
if (workspace != null) {
241-
logger().println("Sending interrupt signal to process");
240+
listener().getLogger().println("Sending interrupt signal to process");
242241
LOGGER.log(Level.FINE, "stopping process", cause);
243242
stopTask = Timer.get().schedule(new Runnable() {
244243
@Override public void run() {
245244
stopTask = null;
246245
if (recurrencePeriod > 0) {
247246
recurrencePeriod = 0;
248-
logger().println("After 10s process did not stop");
247+
listener().getLogger().println("After 10s process did not stop");
249248
getContext().onFailure(cause);
250249
}
251250
}
252251
}, 10, TimeUnit.SECONDS);
253252
controller.stop(workspace, launcher());
254253
} else {
255-
logger().println("Could not connect to " + node + " to send interrupt signal to process");
254+
listener().getLogger().println("Could not connect to " + node + " to send interrupt signal to process");
256255
recurrencePeriod = 0;
257256
super.stop(cause);
258257
}
@@ -312,25 +311,26 @@ private void check() {
312311
if (workspace == null) {
313312
return; // slave not yet ready, wait for another day
314313
}
314+
TaskListener listener = listener();
315315
try (Timeout timeout = Timeout.limit(10, TimeUnit.SECONDS)) {
316-
if (controller.writeLog(workspace, logger())) {
316+
if (controller.writeLog(workspace, listener.getLogger())) {
317317
getContext().saveState();
318318
recurrencePeriod = MIN_RECURRENCE_PERIOD; // got output, maybe we will get more soon
319319
} else {
320320
recurrencePeriod = Math.min((long) (recurrencePeriod * RECURRENCE_PERIOD_BACKOFF), MAX_RECURRENCE_PERIOD);
321321
}
322-
Integer exitCode = controller.exitStatus(workspace, launcher());
322+
Integer exitCode = controller.exitStatus(workspace, launcher(), listener);
323323
if (exitCode == null) {
324324
LOGGER.log(Level.FINE, "still running in {0} on {1}", new Object[] {remote, node});
325325
} else {
326-
if (controller.writeLog(workspace, logger())) {
326+
if (controller.writeLog(workspace, listener.getLogger())) {
327327
LOGGER.log(Level.FINE, "last-minute output in {0} on {1}", new Object[] {remote, node});
328328
}
329329
if (returnStatus || exitCode == 0) {
330330
getContext().onSuccess(returnStatus ? exitCode : returnStdout ? new String(controller.getOutput(workspace, launcher()), encoding) : null);
331331
} else {
332332
if (returnStdout) {
333-
logger().write(controller.getOutput(workspace, launcher())); // diagnostic
333+
listener.getLogger().write(controller.getOutput(workspace, launcher())); // diagnostic
334334
}
335335
getContext().onFailure(new AbortException("script returned exit code " + exitCode));
336336
}
@@ -341,7 +341,7 @@ private void check() {
341341
LOGGER.log(Level.FINE, "could not check " + workspace, x);
342342
ws = null;
343343
if (!printedCannotContactMessage) {
344-
logger().println("Cannot contact " + node + ": " + x);
344+
listener.getLogger().println("Cannot contact " + node + ": " + x);
345345
printedCannotContactMessage = true;
346346
}
347347
}

0 commit comments

Comments
 (0)