Can not run build on Jenkins
tobernguyen opened this issue · comments
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
I've updated the Dockerfile to address this.
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
I can't replicate this I am afraid. How did you start the Jenkins container?
What does the shell build script look like?
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```
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.
Try:
sudo chown -R 1000:1000 /var/jenkins_home
What distro is this?
You mean the local computer? I'm on OS X Yosemite 10.10.5
Ah okay. Hmmm. I've never tried this on an OSX host. Let me do that now.
I don't think this is going to work on OSX.
Hmm.. No workaround? Ok I will try it on Linux later.
Afraid not that I can think of off the top of my head. The way Docker for Mac works makes this tricky.