Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins user is gone after macOS update

I'm running Jenkins as a CI server on a Mac. It was running fine on macOS 10.12 with the typical setup with user jenkins.

Today I upgraded macOS to 10.13 (High Sierra). Jenkins could not start after the upgrade process completed. Furthermore, there was no user jenkins on the system. All Jenkins files are there, but there is no jenkins user in Settings -> Users & Groups. If I try to use jenkins user in Terminal, for instance if I try to change file ownership to jenkins with chown, I get:

chown: jenkins: illegal user name

How do I fix this?

like image 846
Vladimir Grigorov Avatar asked Nov 02 '17 15:11

Vladimir Grigorov


People also ask

Where is Jenkins folder Mac?

Apparently directory path its pointing to /Users/my_user/. jenkins and after some search for my old jobs they are located at /Users/Shared/Jenkins/Home/jobs.

Where is Jenkins initial admin password Mac?

Click on the "+" at the left bottom corner of the pop up window and add the user 4.5 Click on Settings icon - left bottom and Apply changes. Open the "secrets" folder and find the initialAdminPassword file to get the initial admin password.

Does Jenkins work on Mac?

Jenkins is a platform that is autonomous, and can be used on Windows, Mac or any other operating system.

How to manage users in Jenkins?

Step 1: Go to Jenkins dashboard and click on the "Manage Jenkins " link, as highlighted below: Step 2: As soon as we will click on Manage Jenkins, we will be redirected to the Manage Jenkins Page. Now, click on the "Manage Users" under the Security section on the Manage Jenkins page.

How to run Jenkins on a Mac?

To do it, go to System logs in the Jenkins configuration : Save your configuration. After configuration, when you run a job with a Mac Cloud label, it will create a jenkins agent on the mac you setted as host and run the build on it. Zombie process : Sometimes, "sysadminctl" tool continue to run after task executed.

How to fix jenkins-66374 sudoers file on the Mac?

This functionality has been developed to fix JENKINS-66374 sudoers file on the Mac must be updated to add sudo NOPASSWD on all commands needed to create the user with dscl (see Configure a Jenkins User ). You can define a custom LOGGER to log every output of the plugin on the same place. To do it, go to System logs in the Jenkins configuration :

What do you call people who use Jenkins?

These people are generally called users concerning those tools. As far as Jenkins is concerned, a large number of users use this tool for running the jobs daily but for security as well as authorization purpose, Jenkins admin can not provide all the roles to all the users.


2 Answers

You Jenkins configuration still exist under Library/LaunchDaemons/org.jenkins-ci.plist but after the updating for the OS to High Sierra, the Jenkins user got disappear.

So, first you have to create the jenkins user manually from System Preferences/Users & Groups

Account name: jenkins, Full name: Jenkins

After that you have to setup the jenkins configuration to this new user created

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

Finally unload and load jenkins server

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

Enter to http://localhost:8080 in Safari and you will be able to see you jenkins server

like image 100
westrada Avatar answered Nov 16 '22 00:11

westrada


I've managed to re-create jenkins user by extracting the script commands that create it from Jenkins installation. I ran this script in particular:

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
like image 33
Vladimir Grigorov Avatar answered Nov 16 '22 02:11

Vladimir Grigorov