Privileges for jenkins at apache's folder

11,585

Solution 1

After a long and fruitful discussion in the comments, and following this link the user managed to solve the problem adding

--no-perms --omit-dir-times

to the rsync options.

Preliminary attempts to solve the issue:

I guess if security does not concern you for a short period of time, you can try

chmod a+rwx /var/www/app 

and then try to write to this directory. Note that if there are subdirectories you must do it recursively with:

chmod --recursive a+rwx /var/www/app 

If it's successful, then you can start removing permissions gradually and this will help you pinpoint the problem.

Verify that the user jenkins is already a group member of apache with

groups apache

Solution 2

I had a similar issue. I wanted to write to /var/www on localhost in Jenkins. On my server /var/www is owned by www-data, so I added jenkins to www-data group and made /var/www group writable but kept getting permission denied error. Simply restarting jenkins service fixed the issue for me.

Share:
11,585

Related videos on Youtube

Mr.TK
Author by

Mr.TK

Updated on September 18, 2022

Comments

  • Mr.TK
    Mr.TK almost 2 years

    I'm having issue similar to this: How to copy files as Jenkins "post build" action if i don't have privileges to destination directory

    I'm willing to move/copy/rsync files from jenkins workspace to

    /var/www/app

    with rights setted to

    apache:apache

    I've added jenkins to group apache, but the instance of jenkins cannot copy files to /var/www/app.

    I've also tried with setting privileges of /var/www/app to apache:jenkins but still, Jenkins keep spitting out error: Permission denied or Operation not permitted

    PS: Forgot to add OS is centOS ;)

    EDIT 1: This is log from jenkins script runnig:

    [workspace] $ /bin/sh -xe /tmp/hudson1379987233097some_more_numbers.sh + sh /path_to_sh_script/script.sh sending incremental file list

    application/

    rsync: failed to set permissions on "/var/www/app/application": Operation not permitted (1)

    And this is the script itself :)

    #!/bin/bash

    rsync -avzh /path/to/jenkins/jobs/app/workspace/default/application /var/www/app ;

    rsync -avzh /path/to/jenkins/jobs/app/workspace/default/library /var/www/app ;

    rsync -avzh /path/to/jenkins/jobs/app/workspace/default/public /var/www/app ;

    • Karlson
      Karlson about 10 years
      Have you checked that directories are group writeable?
    • Mr.TK
      Mr.TK about 10 years
      @Karlson Thanks for Your idea. But still... those are 0774. And this just doesn't work. :/
  • Mr.TK
    Mr.TK about 10 years
    Really great thanks for Your answer! Hope it will help and i will be able to give You all this reputation points!! All happens at very same server. :) How to do that on the same server?
  • Mr.TK
    Mr.TK about 10 years
    Do You know or not? :) Bounty is expiring! :) And I cannot accept Your answer without checking if it's correct and I kinda don't know how to! :) Do I have to login via ssh at localhost on user jenkins or apache? Or root-like account? Because both apache and jenkins are "not able to login" accounts.
  • Mr.TK
    Mr.TK about 10 years
    $ groups apache apache : apache jenkins And i did granted all priviliges to group apache, then after no succes changed it to apache:jeknins and even this didn't help. :(
  • Konstantinos
    Konstantinos about 10 years
    If the "others" have rwx can you write even one file on this directory or not? Your username is small case right? E.g. jenkins and not Jenkins?
  • Konstantinos
    Konstantinos about 10 years
    Also, if you are using another disk for /var or one of the relevant subdirectories, it is mounted as writable, right?
  • Mr.TK
    Mr.TK about 10 years
    No :/ rsync: failed to set permissions on "/var/www/app": Operation not permitted (1)
  • Konstantinos
    Konstantinos about 10 years
    Can you please copy/paste the exact commands you are using? Do you have ssh access to the server?
  • Mr.TK
    Mr.TK about 10 years
    I don't think there is another disk involved - it's OVH vps and mount didn't show that /var is mounted elsewhere
  • Konstantinos
    Konstantinos about 10 years
    Can you please copy/paste the /etc/rsyncd.conf? Maybe the configuration does not allow you to write.
  • Mr.TK
    Mr.TK about 10 years
    Check question edit: "EDIT 1" :)
  • Mr.TK
    Mr.TK about 10 years
    /etc/rsyncd.conf: No such file or directory
  • Konstantinos
    Konstantinos about 10 years
    I think this is the problem: superuser.com/questions/299939/… If you have ssh access to the server you can also try compressing your local files, sending them over ssh with scp and then ssh on the server and decompress them there.
  • Mr.TK
    Mr.TK about 10 years
    Thanks for getting me there :) I've founded the answer. Add this to Your answer and I will happily accept it: ADD OPTIONS: --no-perms --omit-dir-times to RSYNC command
  • shawty
    shawty over 3 years
    Same with me, I've been throwing this one around for three hours now, restarted jenkins... and yep.. solved. It's the same as if you add yourself to a group while logged in, you have to log-out then back in for it to take effect, it's no different with jenkins.