mackins更新后,Jenkins用户不见了

时间:2017-11-02 15:32:34

标签: macos jenkins macos-high-sierra

我在Mac上运行Jenkins作为CI服务器。它在macOS 10.12上正常运行,具有用户jenkins的典型设置。

今天我将macOS升级到10.13(High Sierra)。升级过程完成后,Jenkins无法启动。此外,系统上没有用户jenkins。所有Jenkins文件都在那里,但设置中没有jenkins用户 - >用户&组。如果我尝试在终端中使用jenkins用户,例如,如果我尝试将文件所有权更改为带有chown的jenkins,我会得到:

chown: jenkins: illegal user name

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:19)

你的Jenkins配置仍然存在于 Library / LaunchDaemons / org.jenkins-ci.plist 下,但在将操作系统更新到High Sierra之后,Jenkins用户就消失了。

因此,首先您必须从系统偏好设置/用户&处理器手动创建jenkins用户。组

  

帐户名称:jenkins,全名:Jenkins

之后,您必须将jenkins配置设置为此新用户

  • sudo chown -R jenkins / Users / Shared / Jenkins
  • sudo chown jenkins / var / log / jenkins

最后卸载并加载jenkins服务器

  • sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
  • sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

在Safari中输入http://localhost:8080,您将能够看到jenkins服务器

答案 1 :(得分:9)

我设法通过提取从Jenkins安装创建它的脚本命令来重新创建jenkins用户。我特别运行了这个脚本:

JENKINS_HOMEDIR="/Users/Shared/Jenkins"
DEFAULTS_PLIST="/Library/Preferences/org.jenkins-ci.plist"

if dscl . -list /Users/jenkins; then
    echo 'jenkins user already exists, attempting to change the shell to /bin/bash'
    # Will fail if UserShell is not /usr/bin/false, but that's ok.
    # Then we will assume an admin has changed it.
    dscl . -change /Users/jenkins UserShell /usr/bin/false /bin/bash
else
    echo 'No jenkins user found, creating jenkins user and group'

# Find free uid under 500
    uid=$(dscl . -list /Users uid | sort -nrk 2 | awk '$2 < 500 {print $2 + 1; exit 0}')
    if [ $uid -eq 500 ]; then
        echo 'ERROR: All system uids are in use!'
        exit 1
    fi
    echo "Using uid $uid for jenkins"

    gid=$uid
    while dscl -search /Groups gid $gid | grep -q $gid; do
        echo "gid $gid is not free, trying next"
        gid=$(($gid + 1))
    done
    echo "Using gid $gid for jenkins"

    dscl . -create /Groups/jenkins PrimaryGroupID $gid

    dscl . -create /Users/jenkins UserShell /bin/bash
    dscl . -create /Users/jenkins Password '*'
    dscl . -create /Users/jenkins UniqueID $uid
    dscl . -create /Users/jenkins PrimaryGroupID $gid
    dscl . -create /Users/jenkins NFSHomeDirectory "$JENKINS_HOMEDIR"

    dscl . -append /Groups/jenkins GroupMembership jenkins
fi

# identify the real default group name for user jenkins
groupid=`dscl . read /Users/jenkins PrimaryGroupID | awk '{print $2}'`
gname=`id -n -g $groupid`

echo "Using jenkins:${gname} as file owner and group for jenkins daemon files"

find "$JENKINS_HOMEDIR" \( -not -user jenkins -or -not -group ${gname} \) -print0 | xargs -0 chown jenkins:${gname}

# Add defaults for heap sizing
arch=$(uname -m)
if [ $arch = 'x86_64' ]; then
    defaults write $DEFAULTS_PLIST heapSize 512m
    defaults write $DEFAULTS_PLIST permGen 512m
    defaults write $DEFAULTS_PLIST minHeapSize 256m
    defaults write $DEFAULTS_PLIST minPermGen 256m
else
    # i386
    defaults write $DEFAULTS_PLIST heapSize 128m
    defaults write $DEFAULTS_PLIST permGen 128m
    defaults write $DEFAULTS_PLIST minHeapSize 64m
    defaults write $DEFAULTS_PLIST minPermGen 64m    
fi

defaults write $DEFAULTS_PLIST httpPort 8080

# Set tmpdir
JENKINS_TMPDIR="$JENKINS_HOMEDIR/tmp"
defaults write $DEFAULTS_PLIST tmpdir $JENKINS_TMPDIR
mkdir -p $JENKINS_TMPDIR
chown jenkins:${gname} $JENKINS_TMPDIR

# Create log directory, which can be written by Jenkins daemon
mkdir -p /var/log/jenkins
chown jenkins:${gname} /var/log/jenkins