How to run jenkins as a different user

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:

  • using CCtray with Jenkins, while security enabled (using HTTPS)
  • Jenkins: deploying war files from artifactory
  • Testing/previewing Github branches on a dev server
  • What is the difference between Hudson and CruiseControl for Java projects?
  • Should I store a database backup used for our automated tests in git?
  • Should Git be used to store continuous integration builds?
    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?

  • How to parse JSON response in a built step in jenkins
  • Hudson git error ssh
  • Disable “Accept Merge Request” button based on GitLab CI status and/or SonarQube results
  • Visual Studio Online isn't deploying .js files from TypeScript compilation to Azure
  • How to choose between Hudson and Jenkins?
  • How to send “back to normal” notifications in Jenkins Declarative Pipeline?
  • 5 Solutions collect form web for “How to run jenkins as a different user”

    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, go to Manage Jenkins > Configure System. You should see the options there.

    ===========================================================================

    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 https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin to see how to set up Jenkins to work with your git repository.

    Hope that helps.

    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:

    Step 1

    The main thing is to update the JENKINS_USER environment variable. Here’s a patch showing how to change the user to ptran.

    BEGIN PATCH

    --- 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

    Step 2

    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
    

    Step 3

    Restart jenkins

    sudo service jenkins restart
    

    On Mac OS X, the way I enabled Jenkins to pull from my (private) Github repo is:

    First, ensure that your user owns the Jenkins directory

    sudo chown -R me:me /Users/Shared/Jenkins
    

    Then edit the LaunchDaemon plist for Jenkins (at /Library/LaunchDaemons/org.jenkins-ci.plist) so that your user is the GroupName and the UserName:

        <key>GroupName</key>
        <string>me</string>
    ...
        <key>UserName</key>
        <string>me</string>
    

    Then reload Jenkins:

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

    Then Jenkins, since it’s running as you, has access to your ~/.ssh directory which has your keys.

    If you really want to run Jenkins as you, I suggest you check out my Jenkins.app. An alternative, easy way to run Jenkins on Mac.

    See https://github.com/stisti/jenkins-app/

    Download it from https://github.com/stisti/jenkins-app/downloads

    you can integrate to LDAP or AD as well. It works well.

    Git Baby is a git and github fan, let's start git clone.