Fix WithContainerStep when hasWorkdir is false for Windows Containers #370
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The existing logic in the Decorator class sets hasWorkDir if the docker version is newer than 17.12. In the case where hasWorkDir is false, the fallback logic in the decorate() method updates the starter cmds() but always uses a UNIX-like "sh" command, which causes Jenkins to hang and timeout when using Windows Containers.
Update the logic in the decorate() method to provide an implementation for Windows Containers that prepends the appropriate "cd" command followed by && to the generated command.
Testing done
This change was tested using Jenkins to build Windows Containers using
nerdctl/containerdas a Docker replacement using the docker-workflow-plugin. The codepath in question is not normally used, but is triggered becausenerdctlreports a version of 2.1.6 which is earlier than 17.12.Without this patch, Jenkins hangs when executing the
batcontainer step due to the UNIX-style "sh" fallback implemented which blocks and eventually causes the build to timeout.If the automated test coverage is using the official Docker installer then it is impossible to trigger this codepath because it always reports a version later than 17.12.
Related issues:
https://issues.jenkins.io/browse/JENKINS-75102
#326
Submitter checklist