7
votes

I'm running Jenkins 1.433 on Ubuntu 11.04 in order to perform a build which includes an Ant task. The clean portion of my Ant task, which deletes the build directory from prior builds, will work when running sudo Ant from the terminal, but fails from Jenkins with the following:

BUILD FAILED
/var/lib/jenkins/workspace/AomaTests/build.xml:47: Unable to delete directory /var/lib/jenkins/workspace/AomaTests/build

The Ant install referenced by Jenkins is the one which works from the command line (usr/bin/ant), and the Jenkins project specifically points to this instance (and not to Default). Figuring this was a permissions problem, I tried the following:

  • chown -R the appropriate build directory, setting its owner to jenkins.
  • Doing a chmod 777 on the directory.
  • Temporarily allowing the jenkins username the ability to run things without a pasword (via editing the sudoers file with the line jenkins ALL = NOPASSWD:ALL).

None of these approaches workd. Should I be running ant via a different user, or perhaps passing it some properties via Jenkins?

Update: The output of ps -ef | grep "jenkins" is:

jenkins   1647     1  0 12:28 ?        00:00:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -jar /usr/share/jenkins/jenkins.war --webroot=/var/run/jenkins/war --httpPort=8080 --ajp13Port=-1
jenkins   1660  1647  7 12:28 ?        00:00:13 /usr/bin/java -jar /usr/share/jenkins/jenkins.war --webroot=/var/run/jenkins/war --httpPort=8080 --ajp13Port=-1
mattcarp  2393  2229  0 12:31 pts/0    00:00:00 grep --color=auto jenkins

Running ls -l on the directory that fails to be deleted (when run from Jenkins) shows:

drwxr-xr-x 2 jenkins root 4096 2011-10-03 14:49 build

Many thanks for any advice!

2
Very interesting your setup. Our Jenkins workspace is in /home/jenkins and not /usr/lib/jenkins. I also don't see the job name in the directory structure. In ours, the directory would be /home/jenkins/aromaTest/workspace/build.xml - David W.

2 Answers

7
votes

As it turns out, all that was required was to set the parent directory's owner to jenkins.

Wow - that was a long way to go for such a simple answer!

1
votes

Who is running Jenkins? That's the question. There is some user that's running the Java process that's running the Jenkins server. You need to find that user. Try this:

 $ ps -ef | grep "jenkins"

and see what you get.

Knowing that your name is Matt and I see that the file that can't be deleted is in the /home/mattcarp directory, something tells me there's something screwy going on. My first guess is that Jenkins is not being executed by the user mattcarp.

  • How is Jenkins installed? Is it installed as its own user in its own directory? That's usually how it is done. For example, you install Jenkins in /home/jenkins, and all the jobs are in /home/jenkins/jobs, and the workspace for a for job foo is in /home/jenkins/jobs/foo/workspace. Why is Jenkins looking at your $HOME directory?
  • How does your Ant build.xml file work? Are you hard coding the directory /home/mattcarp/workspace/... in the build.xml file? If you are, you need to redo your build.xml to use its current directory tree and not hard code it.