Skip to content

Commit

Permalink
Fix some issues with dockerNode mixed with node (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored May 23, 2023
1 parent 0b40f9f commit afae1ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Avoid exposing ourselves to a bug introduced in https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/180 -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>994.vd57e3ca_46d24</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>1199.v02b_9244f8064</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.slaves.Cloud;
import hudson.slaves.WorkspaceList;
import io.jenkins.docker.DockerComputer;
import io.jenkins.docker.DockerTransientNode;
import io.jenkins.docker.client.DockerAPI;
import io.jenkins.docker.connector.DockerComputerAttachConnector;
Expand All @@ -25,6 +28,7 @@
import org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.DynamicContext;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.workflow.support.actions.WorkspaceActionImpl;
Expand Down Expand Up @@ -202,6 +206,10 @@ private void invokeBody(DockerTransientNode node, TaskListener listener) {
env.put("EXECUTOR_NUMBER", "0");
env.put("NODE_LABELS", join(node.getAssignedLabels(), " "));
env.put("WORKSPACE", ws.getRemote());
FilePath tempDir = WorkspaceList.tempDir(ws);
if (tempDir != null) {
env.put("WORKSPACE_TMP", tempDir.getRemote()); // JENKINS-60634
}
} catch (IOException | InterruptedException e) {
getContext().onFailure(e);
}
Expand All @@ -213,6 +221,20 @@ private void invokeBody(DockerTransientNode node, TaskListener listener) {
.start();
}

@Extension
public static final class ProvideDockerTransientNode extends DynamicContext.Typed<DockerTransientNode> {
@Override
protected Class<DockerTransientNode> type() {
return DockerTransientNode.class;
}

@Override
protected DockerTransientNode get(DelegatedContext context) throws IOException, InterruptedException {
Computer c = context.get(Computer.class);
return c instanceof DockerComputer ? ((DockerComputer) c).getNode() : null;
}
}

private static String join(Collection<?> objects, String delimiter) {
return objects.stream().map(Object::toString).collect(Collectors.joining(delimiter));
}
Expand Down

0 comments on commit afae1ff

Please sign in to comment.