From afae1ff6c534805c06b07f355e5fa875188edc98 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 23 May 2023 11:30:58 -0400 Subject: [PATCH] Fix some issues with `dockerNode` mixed with `node` (#957) --- pom.xml | 11 ---------- .../pipeline/DockerNodeStepExecution.java | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 772c123b..c4ab6478 100644 --- a/pom.xml +++ b/pom.xml @@ -81,17 +81,6 @@ pom import - - - org.jenkins-ci.plugins.workflow - workflow-basic-steps - 994.vd57e3ca_46d24 - - - org.jenkins-ci.plugins.workflow - workflow-durable-task-step - 1199.v02b_9244f8064 - diff --git a/src/main/java/io/jenkins/docker/pipeline/DockerNodeStepExecution.java b/src/main/java/io/jenkins/docker/pipeline/DockerNodeStepExecution.java index da7a2921..6c4a9a24 100644 --- a/src/main/java/io/jenkins/docker/pipeline/DockerNodeStepExecution.java +++ b/src/main/java/io/jenkins/docker/pipeline/DockerNodeStepExecution.java @@ -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; @@ -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; @@ -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); } @@ -213,6 +221,20 @@ private void invokeBody(DockerTransientNode node, TaskListener listener) { .start(); } + @Extension + public static final class ProvideDockerTransientNode extends DynamicContext.Typed { + @Override + protected Class 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)); }