@@ -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 ();
0 commit comments