12

I have a strange problem in jenkins, I cannot copy files in a job, however, with the user jenkins on the command line, I can do that without problem.

I am using jenkins on debian running under the user "jenkins".

I added the user "jenkins" to the group "www-data", so that I can copy files to the www-folder of apache.

The folder rights of the target folder look like this:

drwxrwxr-x 9 www-data www-data 4096 Jun 23 16:19 .   
drwxrwxr-x 4 www-data www-data 4096 Jun 23 12:45 ..  
-rw-rw-r-- 1 volker   www-data  368 Jun 23 17:10 about.php  
-rw-rw-r-- 1 volker   www-data  366 Jun 23 17:10 bio.php  
-rw-rw-r-- 1 volker   www-data  370 Jun 23 17:10 contact.php   
drwxrwxr-x 3 volker   www-data 4096 Jun 23 16:19 content  
drwxrwxr-x 3 volker   www-data 4096 Jun 23 16:19 css  
drwxrwxr-x 8 volker   www-data 4096 Jun 23 16:19 default  
drwxrwxr-x 3 volker   www-data 4096 Jun 23 16:19 fonts  
drwxrwxr-x 2 volker   www-data 4096 Jun 23 13:40 image  
drwxrwxr-x 3 volker   www-data 4096 Jun 23 16:19 images  
-rw-rw-r-- 1 volker   www-data  372 Jun 23 17:10 impressum.php  
-rw-rw-r-- 1 volker   www-data  367 Jun 23 17:10 index.php  
-rw-rw-r-- 1 volker   www-data  296 Jun 23 13:52 kontakt.php  
drwxrwxr-x 3 volker   www-data 4096 Jun 23 16:19 layout   
-rw-rw-r-- 1 volker   www-data  367 Jun 23 17:10 news.php  
-rw-rw-r-- 1 volker   www-data  370 Jun 23 17:10 termine.php  
-rw-rw-r-- 1 volker   www-data  369 Jun 23 17:10 videos.php  

So everything is writable for group www-data.

If I am using the jenkins user to copy the files in the shell, I get no error:

jenkins@rootserver:~/jobs/deploy_notundellende/workspace$ whoami  
jenkins  
jenkins@rootserver:~/jobs/deploy_notundellende/workspace$ cp -R * /var/www/nue  
jenkins@rootserver:~/jobs/deploy_notundellende/workspace$   

But if I use the same command in jenkins itself, it fails with permission error:

pwd  
/var/lib/jenkins/jobs/deploy_notundellende/workspace  
whoami  
jenkins  
cp -R about.php bio.php contact.php content css fonts images impressum.php index.php   layout news.php termine.php videos.php /var/www/nue  
cp: cannot create regular file `/var/www/nue/about.php': Permission denied  
cp: cannot create regular file `/var/www/nue/bio.php': Permission denied  
cp: cannot create regular file `/var/www/nue/contact.php': Permission denied  
cp: cannot create regular file `/var/www/nue/content/videos.php': Permission denied  

How is that possible? Does anyone have an idea?

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
ferrari2k
  • 461
  • 1
  • 5
  • 16
  • OK, I got it to work, I restarted the jenkins server and it worked. I assume it did not work before, because the jenkins server was already running when I changed its permissions. Makes sense to me now, come to think of it :) Anyway, thanks for anybody reading and thinking about this! – ferrari2k Jun 23 '13 at 19:31
  • 1
    provide that as an answer and accept that. That's the way stackoverflow marks a question as resolved. – eis Jun 23 '13 at 20:25

2 Answers2

14

OK, I got it to work, I restarted the jenkins server and it worked. I assume it did not work before, because the jenkins server was already running when I changed its permissions. Makes sense to me now, come to think of it :) Anyway, thanks for anybody reading and thinking about this!

ferrari2k
  • 461
  • 1
  • 5
  • 16
1

Solution 1: Restart Jenkins

(jenkins_url)/safeRestart - Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.

(jenkins_url)/restart - Forces a restart without waiting for builds to complete.

Solution 2: Check the user and permission for the same user

Check user: whoami

change permission: sudo chmod -R 777 /var/www/html/* or sudo chmod a+rwx /var/szDirectoryName

Solution 3:

If you get error/warning like Linux: 'Username' is not in the sudoers file. This incident will be reported ref the link

Srikrushna
  • 4,366
  • 2
  • 39
  • 46