Batch file on Windows not exiting

32 views
Skip to first unread message

Andy Bergh

unread,
Oct 27, 2020, 4:55:13 AM10/27/20
to go-cd
Hi,

I am trying to run a batch file on windows (both agent and server are on Windows)
The batch file is executed but it never exits. I purposefully exit with a '1' to fail.

I am using "start" as the command for the job - is there a better option? When I run the following in the terminal it runs the batch file and exits gracefully:

start "" /b /wait start_docker.bat

But when I run it as a job in the pipeline it just hangs there. I assume that is because for some reason the process is paused and is waiting for the enter or esc key to be pressed.

Any idea how I can make a batch script exit a job when it is complete?

Thanks

Aravind SV

unread,
Oct 27, 2020, 11:18:47 AM10/27/20
to Andy Bergh, go-cd

Hello Andy,

Have you tried just start_docker.bat? What happens with that?

Regards,
Aravind

Andy Bergh

unread,
Oct 27, 2020, 11:30:32 AM10/27/20
to Aravind SV, go-cd
Hello Aravind,

I have tried that yes. It says that start_docker.bat is not an internal or external command.

If I run "cmd" with argument start_docker.bat it succeeds, but in less than a second...which is not correct.

As you can tell from the name I start a docker container which does a few things for about 4 seconds, after which the batch file exits with either a 0 or 1 (based on the docker result).

Any idea what I am doing wrong?

Aravind SV

unread,
Oct 27, 2020, 12:15:18 PM10/27/20
to Andy Bergh, go-cd

Hello Andy,

I’m not sure.

On Windows, GoCD should be running eveything with cmd /c. So, you shouldn’t have to do anything except use start_docker.bat. Maybe it’s a PATH issue which is preventing you from using that?

Might be worth trying to use the whole path to start_docker.bat and checking. If it “hangs” as in when you used start /k etc, it usually means that a child process is keeping the standard output open and not exiting. You could try adding a message before the exit, to see if it reached there (it likely will).

If none of those work, someone with a Windows setup might need to help / might have more ideas.

Cheers,
Aravind

Andy Bergh

unread,
Oct 27, 2020, 12:48:39 PM10/27/20
to Aravind SV, go-cd
Great information thank you Aravind!

Your confirmation of the cmd /c is very helpful. I have tried including the (static) path within the command, which worked in the terminal itself, but "hanged" when the job/command was run in the pipe. I was not using the environment variable PATH.

As an aside, I am not able to see the output of the start_docker.bat file. Even if the bat file simply contains "echo 'Hello World'".

It is evening here but I will certainly look into your PATH suggestion as soon as I can and update this forum if I make any useful findings.

Again, thank you for your suggestions and input.

Kind regards

Andy Bergh

unread,
Oct 28, 2020, 3:20:17 AM10/28/20
to Aravind SV, go-cd
Hi Aravind,

Thanks for your input, because of it I managed to solve my problem. The bat file was not in the correct path.
In other words I did not explicitly tell gocd where to find the bat file. The following fixed that issue for me:
Command:   cd
Arg:              /d D:\path\to\bat\file && cmd /c start_docker.bat

Perhaps not the most elegant, but it works.

I only recently started using GOCD and glanced over the jobs documentation, something I missed was that changing the directory in a previous task within a job does not "carry over" to the next
task. I will look into the documentation on environment variables to perform this task more neatly.

Kind regards


Reply all
Reply to author
Forward
0 new messages