Error ?The working directory must exist before executing the process? when deploying with Bamboo
Asked by Lou Vasilev:

I have a Script task, in Bamboo, for deploying a C# console project to a web server. When run, the task fails with the following error:

```
com.atlassian.bamboo.task.TaskException: Failed to execute task
 at com.atlassian.bamboo.plugins.shell.task.AbstractShellBuildTask.execute(AbstractShellBuildTask.java:84)
 at com.atlassian.bamboo.plugins.script.task.ScriptBuildTask.execute(ScriptBuildTask.java:55)
 at com.atlassian.bamboo.task.TaskExecutorImpl.lambda$executeTasks$272(TaskExecutorImpl.java:317)
 at com.atlassian.bamboo.task.TaskExecutorImpl.executeTaskWithPrePostActions(TaskExecutorImpl.java:246)
 at com.atlassian.bamboo.task.TaskExecutorImpl.executeTasks(TaskExecutorImpl.java:317)
 at com.atlassian.bamboo.task.TaskExecutorImpl.execute(TaskExecutorImpl.java:118)
 at com.atlassian.bamboo.build.pipeline.tasks.ExecuteBuildTask.call(ExecuteBuildTask.java:74)
 at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.build(DefaultBuildAgent.java:215)
 at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl$1.call(BuildAgentControllerImpl.java:139)
 at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl$1.call(BuildAgentControllerImpl.java:130)
 at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:221)
 at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.waitAndPerformBuild(BuildAgentControllerImpl.java:129)
 at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent$1.run(DefaultBuildAgent.java:137)
 at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:51)
 at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:31)
 at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:20)
 at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:52)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: The working directory must exist before executing the process
 at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
 at com.atlassian.bamboo.process.ProcessServiceImpl.createExternalProcess(ProcessServiceImpl.java:157)
 at com.atlassian.bamboo.process.ProcessServiceImpl.executeExternalProcess(ProcessServiceImpl.java:206)
 at com.atlassian.bamboo.plugins.shell.task.AbstractShellBuildTask.execute(AbstractShellBuildTask.java:61)
```

All the task does is copy the release folder of the project in question from a Bamboo build server to a given directory on another server. It's set as an inline task and its script body looks like this:

    xcopy /s /y "${bamboo.build.working.directory}\Source\MyProject\bin\Release" "\\${bamboo.deploy.environment}.mycompany.com\c$\Applications\Stuff\TargetFolder"

Where "${bamboo.deploy.environment}" is equal to "development", and the "Working sub directory" property of the task looks like this:

    location="\\development.mycompany.com\c$\Applications\Stuff\TargetFolder"

I've verified that the `"Source\bin\release"` folder on the Bamboo build server exists and all the release files for `"MyProject"` are present in it, and I've also verified that folder `"c$\Applications\Stuff\TargetFolder"` on sever `"development.mycompany.com"` exists and that it has proper permissions, but I am still getting the error.

The only useful information about this I've been able to find, in [this](https://community.atlassian.com/t5/Bamboo-questions/Bamboo-working-subdirectory-needs-to-be-in-workspace/qaq-p/34297) question from two years ago, alludes to a permission issue of some kind, and that the Bamboo agent performing the deploy might not have permissions to access directory "TargetFolder", but I have not been able to figure out where in Bamboo to change the permissions for the deployment agent.

Any idea why this exception is being thrown and how to change the permissions for a Bamboo deploy agent?


Answers:
author: Foong
body: > the "Working sub directory" property of the task looks like this:

It seems that you are trying to use remote server file URL in the "Working subdirectory" setting.

Script task does not work with remote server file URL. If the Working subdirectory setting is "\\Source\\MyProject\\bin\\Release", it means that the script will be run in the directory "${bamboo.build.working.directory}\\Source\\MyProject\\bin\\Release".

If you would like to run the script in another machine, pease use the SSH Task.

comments: author: Lou Vasilev
body: Yes, that was the problem. I put the remote server file URL in the wrong place. It should be in **Environment variables** , not **Working subdirectory** . Once i put it in Environment variables, it started working.

Thanks.


Tags: bamboo-administration