How to run jenkins as a different user

Viewed 122651

I have been trying to follow tutorials and this one: Deploy as Jenkins User or Allow Jenkins To Run As Different User?

but I still can't for the love of the computing gods, run as a different user. Here are the steps of what I did:

  1. download the macosx pkg for jenkins(LTS)
  2. setup plugins etc and git
  3. try to build it

I keep getting a can't clone error because jenkins keeps starting as anonymous:

Started by user anonymous

How do I set it up so that jenkins runs as me? I was using the jenkins web UI so it was in localhost:8080

I tried logging in also using /login but I can't even login using my name or as root.

The people tab doesn't even have a create user link, so yeah I've been stuck. Help please?

6 Answers

To run jenkins as different user on ubuntu os you need to change below things.

Update below two lines in /etc/default/jenkins file

JENKINS_USER=$USERNAME

JENKINS_GROUP=$NAME

In our case we set user as ubuntu.

#JENKINS_USER=$NAME
#JENKINS_GROUP=$NAME
JENKINS_USER="ubuntu"
JENKINS_GROUP="ubuntu"

Update below two lines in /lib/systemd/system/jenkins.service file

User=jenkins

Group=jenkins

In our case we set user as ubuntu.

#User=jenkins
#Group=jenkins
User=ubuntu
Group=ubuntu

Change file ownership of jenkins owned folders.

sudo chown -R ubuntu:ubuntu /var/lib/jenkins
sudo chown -R ubuntu:ubuntu /var/cache/jenkins
sudo chown -R ubuntu:ubuntu /var/log/jenkins

After above changes run below command to reload systemctl

sudo systemctl daemon-reload

Now you can restart jenkins

sudo systemctl restart jenkins.service
Related