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:
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?
To run a job by a specific user, you have to enable security options in jenkins. May be you have not used the enable security options in Jenkins and that is why it says started by anonymous user. You can create any number of users in Jenkins by providing their credentials.
If you have access to the gui, you can go to "manage jenkins" > "system information" and look for "user.name".
The "Issue 2" answer given by @Sagar works for the majority of git servers such as gitorious.
However, there will be a name clash in a system like gitolite where the public ssh keys are checked in as files named with the username, ie keydir/jenkins.pub
. What if there are multiple jenkins servers that need to access the same gitolite server?
(Note: this is about running the Jenkins daemon not running a build job as a user (addressed by @Sagar's "Issue 1").)
So in this case you do need to run the Jenkins daemon as a different user.
There are two steps:
The main thing is to update the JENKINS_USER
environment variable. Here's a patch showing how to change the user to ptran
.
--- etc/default/jenkins.old 2011-10-28 17:46:54.410305099 -0700 +++ etc/default/jenkins 2011-10-28 17:47:01.670369300 -0700 @@ -13,7 +13,7 @@ PIDFILE=/var/run/jenkins/jenkins.pid # user id to be invoked as (otherwise will run as root; not wise!) -JENKINS_USER=jenkins +JENKINS_USER=ptran # location of the jenkins war file JENKINS_WAR=/usr/share/jenkins/jenkins.war --- etc/init.d/jenkins.old 2011-10-28 17:47:20.878539172 -0700 +++ etc/init.d/jenkins 2011-10-28 17:47:47.510774714 -0700 @@ -23,7 +23,7 @@ #DAEMON=$JENKINS_SH DAEMON=/usr/bin/daemon -DAEMON_ARGS="--name=$NAME --inherit --env=JENKINS_HOME=$JENKINS_HOME --output=$JENKINS_LOG - -pidfile=$PIDFILE" +DAEMON_ARGS="--name=$JENKINS_USER --inherit --env=JENKINS_HOME=$JENKINS_HOME --output=$JENKINS_LOG --pidfile=$PIDFILE" SU=/bin/su
END PATCH Update ownership of jenkins directories:
chown -R ptran /var/log/jenkins chown -R ptran /var/lib/jenkins chown -R ptran /var/run/jenkins chown -R ptran /var/cache/jenkins
Restart jenkins
sudo service jenkins restart
ISSUE 1:
Started by user anonymous
That does not mean that Jenkins started as an anonymous user.
It just means that the person who started the build was not logged in. If you enable Jenkins security, you can create usernames for people and when they log in, the
"Started by anonymous"
will change to
"Started by < username >".
Note: You do not have to enable security in order to run jenkins or to clone correctly.
If you want to enable security and create users, you should see the options at Manage Jenkins > Configure System
.
ISSUE 2:
The "can't clone" error is a different issue altogether. It has nothing to do with you logging in to jenkins or enabling security. It just means that Jenkins does not have the credentials to clone from your git SCM.
Check out the Jenkins Git Plugin to see how to set up Jenkins to work with your git repository.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With