6

I am trying to run shell build command on mac but I get permission denied for e.g. ls /Users/... command.

I see whoami is jenkins, which is different for my uesr login?

I read online I need to run chmod for jenkins user, how do I do that?

I changed file permission using chmod 777?

Do I need to change jenkins user?

user2661518
  • 2,677
  • 9
  • 42
  • 79
  • The `...` in your `ls` command is important for us to see, don't shorten it. Also "run chmod for jenkins user" means nothing to me. `chmod` what file/directory? You changed file permissions, on what? – Kusalananda Jun 19 '16 at 08:45

6 Answers6

5

In linux, e.g. ubuntu, you can add user jenkins to the root group:

sudo usermod -a -G root jenkins

Then restart jenkins:

sudo service jenkins restart

Be aware that, adding jenkins user to root group can make the user too powerful, use with caution

Jonathan L
  • 9,552
  • 4
  • 49
  • 38
3

Maybe you have a problem that jenkins is not a full user. Try this:

Create a user for Jenkins

It’s best to run Jenkins as it’s own user (it can then be limited in the permissions it has), and you’ll want to create a standard (full) user for it.

You can do this through System Preferences, the Server Manager or the command line.

For a local user:

# create an applications group
dseditgroup -o create -n . -u username -p -r ‘Applications’ applications
# get the id for that group
sudo dscl . -read /Groups/applications
# find a unique identifier to give the user
sudo dscl . -list /Users UniqueID
# create the jenkins user
sudo dscl . -create /Users/jenkins
sudo dscl . -create /Users/jenkins PrimaryGroupID 505
sudo dscl . -create /Users/jenkins UniqueID 1026
sudo dscl . -create /Users/jenkins UserShell /bin/bash
sudo dscl . -create /Users/jenkins RealName "Jenkins"
sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins
sudo dscl . -passwd /Users/jenkins
# create and set the owner of the home directory
sudo mkdir /Users/jenkins
sudo chown -R jenkins /Users/jenkins

I found this here: installing jenkins on OS X Yosemite

S.Spieker
  • 7,005
  • 8
  • 44
  • 50
0

In my case, the folder was inside a NFS/Samba/Webdav share, which these scripts seem not able to handle. I created a real folder in my fs and linked it to a subdir in the shared folder. That way, no permission denied errors occur anymore.

Andreas
  • 2,211
  • 1
  • 18
  • 36
0

I had the same issue in Windows, where the only user is tadmin and Jenkins running from CMD with elevated/admin privileges. I am using "content replace plugin" - it runs only once and after that says the file is locked, however Unlocker and other utils do not show anything and yet I cannot delete or rename that file. Restarting Jenkins service and reloading did not help, file was still locked. Only a reboot released the file.

It ended up by using powershell plugin to change content of the file - this runs without issues (some tweaking needed to use jenkins variables and double quotes)

For example, to replace 'img src' -> 'img title="branch, build..." src'

powershell -Command "(gc ad/bootstrapheader.jsp) -replace 'img src', 'img title=""""branch: $env:GIT_BRANCH; build: $env:BUILD_ID"""""" src' | Out-File ad/bootstrapheader.jsp"
Reporter
  • 3,897
  • 5
  • 33
  • 47
Sasha Bond
  • 984
  • 10
  • 13
0

Jenkins user won't have permissions to run a non jenkins user folders or files. Use either to run as some other user in the shell (assuming linux OS) or copy the folders or contents to jenkins default folder.

sh ''' su - - << EOF Commands to run '''

OR

copy folders to jenkins default folder

cp -rp <folder/files/related scripts to run> </usr/lib/jenkins/>

0
  1. open terminal

  2. sudo nano /etc/sudoers

at the end of the file add the following statements:

Jenkins ALL=(ALL) NOPASSWD: ALL

Save and exit

  • 4
    Doing the described steps would lead to a great security risk! Every jenkins call would be done with SUDO rights - means root access. If there is any malicious script executed by the build server (e.g. by dependencies inside a build) this can become a big threat to your infrastructure. – de-jcup Jun 22 '21 at 13:23