Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@

@Override
public void onResume() {
getContext().onFailure(new SynchronousResumeNotSupportedException());
var context = getContext();
context.onFailure(new SynchronousResumeNotSupportedException(context));

Check warning on line 71 in src/main/java/org/jenkinsci/plugins/workflow/steps/AbstractSynchronousNonBlockingStepExecution.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 70-71 are not covered by tests
}

@Override public @NonNull String getStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
@Override
public void onResume() {
if (threadName != null) {
getContext().onFailure(new SynchronousResumeNotSupportedException());
var context = getContext();
context.onFailure(new SynchronousResumeNotSupportedException(context));

Check warning on line 108 in src/main/java/org/jenkinsci/plugins/workflow/steps/GeneralNonBlockingStepExecution.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 107-108 are not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import hudson.util.ClassLoaderSanityThreadFactory;
import hudson.util.DaemonThreadFactory;
import hudson.util.NamingThreadFactory;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -72,7 +74,8 @@

@Override
public void onResume() {
getContext().onFailure(new SynchronousResumeNotSupportedException());
var context = getContext();
context.onFailure(new SynchronousResumeNotSupportedException(context));

Check warning on line 78 in src/main/java/org/jenkinsci/plugins/workflow/steps/SynchronousNonBlockingStepExecution.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 77-78 are not covered by tests
}

@Override public @NonNull String getStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

package org.jenkinsci.plugins.workflow.steps;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* May be reported from {@link StepExecution#onResume} when the step does not support resumption.
* Thrown by default from {@link SynchronousNonBlockingStepExecution},
Expand All @@ -33,8 +37,32 @@
*/
public class SynchronousResumeNotSupportedException extends Exception {

private static final Logger LOGGER = Logger.getLogger(SynchronousResumeNotSupportedException.class.getName());

/**
* @deprecated Use {@link #SynchronousResumeNotSupportedException(StepContext)} instead.
*/
@Deprecated
public SynchronousResumeNotSupportedException() {
super("Resume after a restart not supported for non-blocking synchronous steps");
}

public SynchronousResumeNotSupportedException(StepContext context) {
super(String.format("""
The Pipeline step `%s` cannot be resumed after a controller restart. \
In Scripted syntax, you may wrap its containing `node` block within `retry(conditions: [nonresumable()], count: 2) {...}`, \
or, in Declarative syntax, use the `retries` option to an `agent` directive to allow the stage to be retried.""",
getStepDisplayFunctionName(context))
);
}

private static String getStepDisplayFunctionName(StepContext stepContext) {
StepDescriptor descriptor = null;
try {
descriptor = stepContext.get(StepDescriptor.class);
} catch (IOException | InterruptedException e) {
LOGGER.log(Level.FINE, "Failed to get descriptor: ", e);
}
return descriptor != null ? descriptor.getFunctionName() : "?";

Check warning on line 66 in src/main/java/org/jenkinsci/plugins/workflow/steps/SynchronousResumeNotSupportedException.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 40-66 are not covered by tests
}
}