Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-60473 Containerize workspace paths when running Linux container on Windows host #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mrsonicblue
Copy link

This attempts to address this reported issue:

https://issues.jenkins-ci.org/browse/JENKINS-60473

The main problem is that the plugin uses the host's absolute path for the workspace as a volume mount in the Docker container. This works fine when the OS matches between host and container (e.g., Linux/Linux or Windows/Windows). When running Linux containers on a Windows host, the Windows-style paths (with a drive letter) are not valid.

The code change in this fork detects that it's a mixed environment and converts workspace paths to Linux-compatible versions. This is running in production for my use-case, but it has not been robustly tested.

Linux container on Windows host
@mrsonicblue mrsonicblue changed the title Containerize workspace paths when running Linux container on Windows host JENKINS-60473 Containerize workspace paths when running Linux container on Windows host Jan 3, 2020
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it would be a solution for the issue. looks like it is about causing some code duplication due to the third Docker client being introduced, but it looks OK. CC @Casz who contributed to the original code.

It would be great to add Javadoc to newly introduced APIs, and to also fix code style for opening curly brackets in some methods

else {
dockerClient = new WindowsDockerClient(launcher, node, toolName);
String os = dockerClient.inspect(new EnvVars(), step.image, ".Os");
if (os != null && os.equals("linux")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be actually inverted? There is a lot of Unix operating systems being containerized, but Windows Client is for Windows only?

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

public class WindowsLinuxDockerClient extends WindowsDockerClient {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the code, it would be rather a Unix/POSIX container launcher. Not that important tho

@@ -378,4 +378,113 @@ public ContainerRecord getContainerRecord(@Nonnull EnvVars launchEnv, String con
}
return Arrays.asList(volumes.replace("\\", "/").split("\\n"));
}

public String runCommand() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Javadoc for new API below?

@Bobby862
Copy link

I tested the branch on my Windows Host with execution the pipline example from Using Docker with Pipeline
pipeline {
agent {
docker { image 'node:7-alpine' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}

It results in an Error Message:
sh: can't create /d/Sandbox_GIT/Jenkins_Plugin/docker-workflow-plugin-master/work/workspace/test@tmp/durable-f0f56139/jenkins-log.txt: nonexistent directory sh: can't create /d/Sandbox_GIT/Jenkins_Plugin/docker-workflow-plugin-master/work/workspace/test@tmp/durable-f0f56139/jenkins-result.txt.tmp: nonexistent directory mv: can't rename '/d/Sandbox_GIT/Jenkins_Plugin/docker-workflow-plugin-master/work/workspace/test@tmp/durable-f0f56139/jenkins-result.txt.tmp': No such file or directory process apparently never started in D:\Sandbox_GIT\Jenkins_Plugin\docker-workflow-plugin-master\work\workspace\test@tmp\durable-f0f56139

More information i wrote also here: JENKINS-60473
Is there a possibility, to get the Feature "Executing Linux Docker Container on Windows Host also working?"
My assumption is that the changes are only working, when you have a 2 Node Setup with a Jenkins Master running on Linux and a Jenkins Slave running on Windows. In my case i have only a Jenkins
Master which is running on Windows, which executes the Linux Docker Container direct.

This was referenced Dec 13, 2020
@j-p-e
Copy link

j-p-e commented Dec 22, 2021

@oleg-nenashev how can we make this merge happen ?

@oleg-nenashev oleg-nenashev self-assigned this Dec 24, 2021
@oleg-nenashev
Copy link
Member

Added to my list

@mneumei
Copy link

mneumei commented Jun 22, 2022

Any update here? Seems like this was ready to merge but abandoned, but the issue still remains

@jglick
Copy link
Member

jglick commented Dec 1, 2022

This plugin is generally unmaintained and I do not recommend you use it. Instead directly run docker CLI commands from a build script. Windows-specific issues are particularly risky since we have no CI coverage.

@jglick jglick mentioned this pull request Sep 18, 2023
@ljbkusters
Copy link

Sorry if necrobumping but any update on this? This feature would greatly streamline my build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants