Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit 016e216

Browse files
committed
FEA Override --workdir
1 parent a9bffd4 commit 016e216

File tree

2 files changed

+15
-5
lines changed
  • src/main

2 files changed

+15
-5
lines changed

src/main/java/com/gpuopenanalytics/jenkins/remotedocker/DockerLauncher.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ public void launchContainers() throws IOException, InterruptedException {
136136
private ArgumentListBuilder getlaunchArgs(DockerConfiguration config,
137137
boolean isMain) throws IOException, InterruptedException {
138138
String workspacePath = build.getWorkspace().getRemote();
139+
String workspaceTarget = Optional.ofNullable(
140+
buildWrapper.getWorkspaceOverride())
141+
.orElse(workspacePath);
139142
//Fully resolve the source workspace
140143
String workspaceSrc = Paths.get(workspacePath)
141144
.toAbsolutePath()
@@ -159,7 +162,6 @@ private ArgumentListBuilder getlaunchArgs(DockerConfiguration config,
159162
//TODO Set name? Maybe with build.toString().replaceAll("^\\w", "_")
160163
ArgumentListBuilder args = new ArgumentListBuilder()
161164
.add("run", "-t", "-d")
162-
.add("--workdir", workspacePath)
163165
//Add bridge network for internet access
164166
.add("--network", "bridge");
165167
//Add inter-container network if needed
@@ -168,8 +170,9 @@ private ArgumentListBuilder getlaunchArgs(DockerConfiguration config,
168170
if (isMain) {
169171
//Start a shell to block the container, overriding the entrypoint in case the image already defines that
170172
args.add("--entrypoint", "/bin/sh")
171-
.add("-v", workspaceSrc + ":" + workspacePath)
172-
////Jenkins puts scripts here
173+
.add("--workdir", workspaceTarget)
174+
.add("-v", workspaceSrc + ":" + workspaceTarget)
175+
//Jenkins puts scripts here
173176
.add("-v", tmpSrc + ":" + tmpDest);
174177
}
175178
config.addCreateArgs(this, args, build);
@@ -251,7 +254,10 @@ public Proc dockerExec(Launcher.ProcStarter starter,
251254
ArgumentListBuilder args = new ArgumentListBuilder()
252255
.add("exec");
253256
if (starter.pwd() != null) {
254-
args.add("--workdir", starter.pwd().getRemote());
257+
String path = Optional.ofNullable(
258+
buildWrapper.getWorkspaceOverride())
259+
.orElse(starter.pwd().getRemote());
260+
args.add("--workdir", path);
255261
}
256262
if (addRunArgs) {
257263
buildWrapper.getDockerConfiguration().addRunArgs(this, args, build);
@@ -260,6 +266,10 @@ public Proc dockerExec(Launcher.ProcStarter starter,
260266
args.add(mainContainerId);
261267

262268
args.add("env").add(starter.envs());
269+
if (buildWrapper.getWorkspaceOverride() != null) {
270+
//Override $WORKSPACE inside the container
271+
args.add("WORKSPACE=" + buildWrapper.getWorkspaceOverride());
272+
}
263273

264274
List<String> originalCmds = starter.cmds();
265275
boolean[] originalMask = starter.masks();

src/main/resources/com/gpuopenanalytics/jenkins/remotedocker/RemoteDockerBuildWrapper/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<f:entry title="Debug" field="debug">
4141
<f:checkbox/>
4242
</f:entry>
43-
<f:optionalBlock name="workspaceOverrideOptional" title="Override workspace mount" inline="true">
43+
<f:optionalBlock name="workspaceOverrideOptional" title="Override workspace mount" inline="true" checked="${!empty(instance.workspaceOverride)}">
4444
<f:entry title="Workspace path" field="workspaceOverride">
4545
<f:textbox/>
4646
</f:entry>

0 commit comments

Comments
 (0)