我正在尝试在Mac OS上为jenkins创建单独的用户并使用此用户运行它。 我创建了一个新用户:
# Create the group
sudo dscl . create /Groups/jenkins
sudo dscl . create /Groups/jenkins PrimaryGroupID 300
# Create the user
sudo dscl . create /Users/jenkins
sudo dscl . create /Users/jenkins PrimaryGroupID 300
sudo dscl . create /Users/jenkins UniqueID 300
sudo dscl . create /Users/jenkins UserShell /bin/bash
# Set the users pasword
sudo dscl . passwd /Users/jenkins 123qweASD
# Add the user to the group
sudo dscl . append /Groups/jenkins GroupMembership jenkins
我尝试以jenkins用户身份运行jenkins:
sudo su - jenkins -c run_jenkins.sh
并收到错误:
su: no directory
为jenkins用户创建目录后:
sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins
接下来的错误:
su: unknown login: jenkins
一般情况:
感谢您的帮助!
答案 0 :(得分:8)
UserName <string>
This optional key specifies the user to run the job as. This key is only
applicable when launchd is running as root.
GroupName <string>
This optional key specifies the group to run the job as. This key is only
applicable when launchd is running as root. If UserName is set and Group-
Name is not, the the group will be set to the default group of the user.
答案 1 :(得分:0)
您可能需要使用run_jenkins.sh
的绝对值(假设其为/Users/jenkins/run_jenkins.sh
):
sudo su - jenkins -c /Users/jenkins/run_jenkins.sh
答案 2 :(得分:0)
su -
模拟正常登录,因此要求为常规登录设置帐户(定义shell和主目录等)。除非你出于某些原因需要这个,否则就让sudo这样做:
sudo -u jenkins run_jenkins.sh