Reputation: 4914
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...
Upvotes: 10
Views: 6588
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