I'm having trouble getting Jenkins to write to a directory, however I believe I have set the correct permissions. Jenkins is being run by a user named "jenkins", who belongs to a group called "jenkins-group". The directory in question looks something like this when I
drwxrwxr-x 2 jenkins-group jenkins-group 68 Sep 3 13:01 test_save_data_jenkins_R
I followed the recommended approach as seen in the link below, by creating a group having "rwx" permissions and adding the user running Jenkins to this group. How do I properly allow user jenkins to write to a specific directory under user minecraft home directory?.
So I have given the group "jenkins-group" rwx permissions, which in turn should give the user "jenkins" those permissions as well, since it has this group as a secondary. When I log in to the user "jenkins" from a terminal I'm able to create a new file in this folder using
touch test.txt. However when I run a build from Jenkins with the following commands in execute shell:
cd /apps/models/test_save_data_jenkins_R && whoami && touch test.txt
I get the following error:
+ cd /apps/models/test_save_data_jenkins_R + whoami jenkins + touch test.txt touch: cannot touch ‘test.txt’: Permission denied Build step 'Execute shell' marked build as failure Finished: FAILURE
Notice that the group "jenkins-group" also has rwx permissions to the folders "apps" and "models". I have tried giving the user "jenkins" direct permission using the following command:
$ setfacl -Rm user:jenkins:rwx /apps/models/test_save_data_jenkins_R/
which would result in the script running successfully. However this is really a workaround, and I would like to understand what I'm doing wrong in the previous approach.
jenkins : jenkins jenkins-group
# file: test_save_data_jenkins_R/ # owner: jenkins-group # group: jenkins-group user::rwx group::rwx other::r-x
Running /usr/bin/id in jenkins script gives:
+ /usr/bin/id uid=775(jenkins) gid=895(jenkins) groups=895(jenkins)
Running /usr/bin/id from terminal gives:
uid=775(jenkins) gid=895(jenkins) groups=895(jenkins),1012(jenkins-group)
Notice this happens as well after running safeRestart of jenkins service.