Task returning -1 when running on a remote agent running as a Windows service
Asked by Jerome Durand:

I have a Bamboo remote agent running a Job that basically:

-Checkout a PowerShell script in a sub-directory

- and Run the PowerShell script (This script,among others, build the code from the main directory)

This work perfectly fine when I run the remote agent manually in a terminal, but when the remote agent run as a service (installntservice), the task running the script is failing returning -1.

As I had problem with Git right to checkout the script, I have change the "bamboo-remote-agent" service "Log On As" option from " Local Service" to the windows account username. It solve the Git checkout error I had but not the script failing error.

I have added in /conf/wrapper.conf the following:

wrapper.java.additional.3=-Djava.io.tmpdir="C:\\bamboo_agent\\temp"

(*On Windows, when the Bamboo remote agent is installed as a service under the Local System user account. The temporary folder created by the agent isn't accessible by any other application. To allow enable to that folder, configure the agent to use a commonly accessible temporary folder by defining a new Java property in the service wrapper*.)

but I don't know how I can checkout my script into that temp directory and then run it from a Bamboo task.

Any help would be appreciated.

Thanks,


Answers:
author: Jerome Durand
body: <https://confluence.atlassian.com/bamkb/command-is-not-recognized-as-an-internal-or-external-command-744720688.html>

When Running Bamboo as a Windows service as the local user, make sure you have **no****User variable** "**PATH** " in Environment Variables.


author: Omar Herrera
body: Hi [@Jerome Durand](/t5/user/viewprofilepage/user-id/1192588) I had been working with windows agents for a while and I never need access to temp folder on the agent.

All the code and the script must be on the working directory for example

```
agent-working-directory/   ????    script-folder/ ?       src/
        files.*

```

All files that you need on the agent for made the build need store in this structure.

In my case the call to powershell script is lik this.

![Capture.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/17051i3050A5CE25D99594/image-size/large?v=v2&px=999 "Capture.JPG")

Cheers.

comments: author: Jerome Durand
body: Thank you [@Omar Herrera](/t5/user/viewprofilepage/user-id/186043) for your reply.

Ok I won't bother with temp file then, thanks.

This is pretty much what I am doing.

Basically I have 2 git repositories that are checkout in the first task of the job (Source Code Checkout).

The first repo contain the source code and some files, and the second one some scripts to be run:

So I get the same structure than your example before running my script:

agent-working-directory/

script-folder/

src/

files.\*

I then call my Init script like this:![BambooScript.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/17084i98248EE32F63D82E/image-size/large?v=v2&px=999 "BambooScript.PNG")

This work perfectly fine when I run the agent manually in a terminal but when it is run as a service then the script return -1 directly, the first line of the script isn't even run. I know that the script work as again it work fine when the agent is ran manually.

The only thing that I can think is that my init script interfere with tools and other scripts that are outside of the working directory. But why would that work manually?!

Thanks for your help.

Jerome


author: Omar Herrera
body: Hi [@Jerome Durand](/t5/user/viewprofilepage/user-id/1192588) can you try configured the service run with the same windows account that you are using in command line.

I'm agree with you about the interfere but with the right privilegies you will not problems.

Cheers.


author: Jerome Durand
body: Hi [@Omar Herrera](/t5/user/viewprofilepage/user-id/186043),

As I said in my first post, I already did that. It solved another problem I had with Git but not the script error:

"As I had problem with Git right to checkout the script, I have change the "bamboo-remote-agent" service "Log On As" option from " Local Service" to the windows account username."


author: Omar Herrera
body: Sorry [@Jerome Durand](/t5/user/viewprofilepage/user-id/1192588) my apologize for not being able to help you, my configuration is the same to you.

I'm still thinking that a issue with permission.

Cheers.


author: Jerome Durand
body: Thanks [@Omar Herrera](/t5/user/viewprofilepage/user-id/186043) for your help, after spending some time debugging, I found out that normal Shell script were working fine, and that powershell itself wasn't recognized as an internal or external command even though it was in my System environment variable and recognized when the Bamboo remote was run manually.

And I found the solution on this page:

<https://confluence.atlassian.com/bamkb/command-is-not-recognized-as-an-internal-or-external-command-744720688.html>

When Running Bamboo as a Windows service as the local user, make sure you have no **User variable** "**PATH**" in Environment Variables.


Tags: remote-agent

service