Tom Hennen
Tom Hennen

Reputation: 4914

Jenkins is not waiting for Docker command to finish

I'm trying to get Jenkins to run the following command within docker on a Jenkins slave:

docker run -i -v `pwd`:/opt/myapp -w /opt/myapp -t mydockerimage /bin/bash -c "./setup_dev_env.sh && make all"

The trouble is that when I run this from within Jenkins the Docker process is spawned, but Jenkins doesn't wait for it and returns success immediately. If, however, I replace the Docker command with an infinite loop Jenkins will wait, as expected.

When I run this command from the build slave directly, as the Jenkins user, the system waits for the command to finish (which is what I want to happen).

I've tried doing a docker attach, but that also returns immediately. docker wait will cause Jenkins to wait for it, but I won't see any of the output.

Perhaps I'm going about this all wrong...

  1. How can I get Jenkins to wait for this command to finish?
  2. How can I get Jenkins to display the output of the command running in the docker container?
  3. How can I get the exit code of the command run in Docker to be set such that Jenkins can determine if it succeeded or failed?

Upvotes: 10

Views: 6588

Answers (1)

Tom Hennen
Tom Hennen

Reputation: 4914

It turns out the problem was the -t in the command line. Removing -t caused Jenkins to wait for docker to finish what it was doing.

I had a hunch this was the case because ttys can sometimes be strange and Jenkins is probably using a different type of tty (or not at all) than I am when I'm running the same command at the shell prompt.

In the end, this command worked:

docker run -i -v `pwd`:/opt/myapp -w /opt/myapp mydockerimage /bin/bash -c "./setup_dev_env.sh && make all"

Upvotes: 11

Related Questions