turnbullpress / dockerbook-code

The code and configuration examples from The Docker Book (http://www.dockerbook.com)
927 stars 581 forks source link

Can not run build on Jenkins #29

Closed tobernguyen closed 8 years ago

tobernguyen commented 8 years ago

Hi,

After successfully create container jenkins with your config, I tried to build my first job but the build failed with error: sudo: not found

Full logs:

Started by user admin
Building in workspace /var/jenkins_home/jobs/Docker_test_job/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/jamtur01/docker-jenkins-sample.git # timeout=10
Fetching upstream changes from https://github.com/jamtur01/docker-jenkins-sample.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com/jamtur01/docker-jenkins-sample.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 82216cfafe447662b00832d4a4aca83413cb87fd (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 82216cfafe447662b00832d4a4aca83413cb87fd
 > git rev-list 82216cfafe447662b00832d4a4aca83413cb87fd # timeout=10
[workspace] $ /bin/sh -xe /tmp/hudson5749425719159912621.sh
+ sudo docker build .
/tmp/hudson5749425719159912621.sh: 3: /tmp/hudson5749425719159912621.sh: sudo: not found
+ tail -1
+ awk { print $NF }
+ IMAGE=
+ MNT=/var/jenkins_home/jobs/Docker_test_job/workspace/..
+ sudo docker run -d -v /var/jenkins_home/jobs/Docker_test_job/workspace/..:/opt/project/ /bin/bash -c cd /opt/project/workspace && rake spec
/tmp/hudson5749425719159912621.sh: 9: /tmp/hudson5749425719159912621.sh: sudo: not found
+ CONTAINER=
Build step 'Execute shell' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
jamtur01 commented 8 years ago

I've updated the Dockerfile to address this.

tobernguyen commented 8 years ago

The problem has gone but the build still failed because of other error. It failed on docker run step. Then I view logs from the container: /bin/bash: line 0: cd: /opt/project/workspace: No such file or directory.

I pretty sure that I configured the build correctly.

Full log from Jenkins:

Started by user admin
Building in workspace /var/jenkins_home/jobs/Docker_test_job/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/jamtur01/docker-jenkins-sample.git # timeout=10
Fetching upstream changes from https://github.com/jamtur01/docker-jenkins-sample.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com/jamtur01/docker-jenkins-sample.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 82216cfafe447662b00832d4a4aca83413cb87fd (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 82216cfafe447662b00832d4a4aca83413cb87fd
 > git rev-list 82216cfafe447662b00832d4a4aca83413cb87fd # timeout=10
[workspace] $ /bin/sh -xe /tmp/hudson1345183624554426797.sh
+ sudo docker build .
+ tail -1
+ awk { print $NF }
+ IMAGE=3612f01e5fe9
+ MNT=/var/jenkins_home/jobs/Docker_test_job/workspace/..
+ sudo docker run -d -v /var/jenkins_home/jobs/Docker_test_job/workspace/..:/opt/project/ 3612f01e5fe9 /bin/bash -c cd /opt/project/workspace && rake spec
+ CONTAINER=d8a75856813364103848666aff2fae15e9e2897cb7ecd717a2171b33575a1831
+ sudo docker attach d8a75856813364103848666aff2fae15e9e2897cb7ecd717a2171b33575a1831
Build step 'Execute shell' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
jamtur01 commented 8 years ago

I can't replicate this I am afraid. How did you start the Jenkins container?

jamtur01 commented 8 years ago

What does the shell build script look like?

tobernguyen commented 8 years ago

I run docker on Mac. I start Jenkins container with this:

docker run -d -p 8080:8080 -p 50000:50000 -v ~/code/docker/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jamtur01/jenkins

Everything seems to work properly, I can see the config of Jenkins, the project's data on my local computer at ~/code/docker/jenkins_home.

The shell build script I copied from your repo so it can't be wrong.

# Build the image to be used for this job.
IMAGE=$(sudo docker build . | tail -1 | awk '{ print $NF }')

# Build the directory to be mounted into Docker.
MNT="$WORKSPACE/.."

# Execute the build inside Docker.
CONTAINER=$(sudo docker run -d -v $MNT:/opt/project/ $IMAGE /bin/bash -c 'cd /opt/project/workspace && rake spec')

# Attach to the container so that we can see the output.
sudo docker attach $CONTAINER

# Get its exit code as soon as the container stops.
RC=$(sudo docker wait $CONTAINER)

# Delete the container we've just used.
sudo docker rm $CONTAINER

# Exit with the same value as that with which the process exited.
exit $RC```
jamtur01 commented 8 years ago

Try:

sudo docker run -d -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jamtur01/jenkins

Your workspace expects to find the project in the right place I think.

tobernguyen commented 8 years ago

Container exit with error:

touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

The permission of jenkins_home on local computer screen shot 2016-08-14 at 10 40 55 pm

jamtur01 commented 8 years ago

Try:

sudo chown -R 1000:1000 /var/jenkins_home
tobernguyen commented 8 years ago

Same error

touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

Permission changed screen shot 2016-08-14 at 10 52 18 pm

jamtur01 commented 8 years ago

What distro is this?

tobernguyen commented 8 years ago

You mean the local computer? I'm on OS X Yosemite 10.10.5

jamtur01 commented 8 years ago

Ah okay. Hmmm. I've never tried this on an OSX host. Let me do that now.

jamtur01 commented 8 years ago

I don't think this is going to work on OSX.

tobernguyen commented 8 years ago

Hmm.. No workaround? Ok I will try it on Linux later.

jamtur01 commented 8 years ago

Afraid not that I can think of off the top of my head. The way Docker for Mac works makes this tricky.