jenkins build failure shell command permission denied

半世苍凉 提交于 2021-01-21 08:40:57

问题


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?


回答1:


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




回答2:


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




回答3:


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.




回答4:


i have the same issue in Widows, where the only user is the admin 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 locked. only reboot released the file.

i 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"


来源:https://stackoverflow.com/questions/37903334/jenkins-build-failure-shell-command-permission-denied

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!