How do I run Jenkins with a specific working directory and a specific user account?2019 Community Moderator ElectionInit script to run a script as specific userIf I set java bin PATH Dockerfile Jar Command runs but tomcat doesn'tHow to run builds in Docker containers from JenkinsOutput is not getting written in nohup.out while starting the server from jenkinsHow to run a jar together with faketimeHow to run pgpool(or any service) through postgres(any specific) userJenkins in Docker doesn't have access to /dev/vboxnetctl for VirtualBoxJenkins write permission on linuxInvoke UI from pseudo consoleJenkins Docker exec : No such file or Directory

Multi tool use
Multi tool use

What should be the ideal length of sentences in a blog post for ease of reading?

What the heck is gets(stdin) on site coderbyte?

How do you justify more code being written by following clean code practices?

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

The Digit Triangles

Did I make a mistake by ccing email to boss to others?

Mimic lecturing on blackboard, facing audience

SOQL query causes internal Salesforce error

How to reduce predictors the right way for a logistic regression model

Pre-Employment Background Check With Consent For Future Checks

Showing mass murder in a kid's book

What is the meaning of "You've never met a graph you didn't like?"

Why is participating in the European Parliamentary elections used as a threat?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Why the various definitions of the thin space ,?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Anime with legendary swords made from talismans and a man who could change them with a shattered body

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Difference between shutdown options

Can I say "fingers" when referring to toes?

Do I have to know the General Relativity theory to understand the concept of inertial frame?

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?



How do I run Jenkins with a specific working directory and a specific user account?



2019 Community Moderator ElectionInit script to run a script as specific userIf I set java bin PATH Dockerfile Jar Command runs but tomcat doesn'tHow to run builds in Docker containers from JenkinsOutput is not getting written in nohup.out while starting the server from jenkinsHow to run a jar together with faketimeHow to run pgpool(or any service) through postgres(any specific) userJenkins in Docker doesn't have access to /dev/vboxnetctl for VirtualBoxJenkins write permission on linuxInvoke UI from pseudo consoleJenkins Docker exec : No such file or Directory










1















I am executing below jenkins.war with below command



 jenkins -jar jenkins.war


But I want to specify to use below path while executing the war



 `/data/jenkins`


and it should run as jenkins user . Right now it is getting executed as root user and under /root directory



How can I achieve that ?










share|improve this question
























  • Did you create the user jenkins?

    – Panki
    yesterday











  • Also, did you create /data dir?

    – nwildner
    yesterday















1















I am executing below jenkins.war with below command



 jenkins -jar jenkins.war


But I want to specify to use below path while executing the war



 `/data/jenkins`


and it should run as jenkins user . Right now it is getting executed as root user and under /root directory



How can I achieve that ?










share|improve this question
























  • Did you create the user jenkins?

    – Panki
    yesterday











  • Also, did you create /data dir?

    – nwildner
    yesterday













1












1








1


0






I am executing below jenkins.war with below command



 jenkins -jar jenkins.war


But I want to specify to use below path while executing the war



 `/data/jenkins`


and it should run as jenkins user . Right now it is getting executed as root user and under /root directory



How can I achieve that ?










share|improve this question
















I am executing below jenkins.war with below command



 jenkins -jar jenkins.war


But I want to specify to use below path while executing the war



 `/data/jenkins`


and it should run as jenkins user . Right now it is getting executed as root user and under /root directory



How can I achieve that ?







rhel java jenkins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 20 hours ago









Haxiel

3,35511021




3,35511021










asked yesterday









Zama QuesZama Ques

94282743




94282743












  • Did you create the user jenkins?

    – Panki
    yesterday











  • Also, did you create /data dir?

    – nwildner
    yesterday

















  • Did you create the user jenkins?

    – Panki
    yesterday











  • Also, did you create /data dir?

    – nwildner
    yesterday
















Did you create the user jenkins?

– Panki
yesterday





Did you create the user jenkins?

– Panki
yesterday













Also, did you create /data dir?

– nwildner
yesterday





Also, did you create /data dir?

– nwildner
yesterday










2 Answers
2






active

oldest

votes


















0














I used environmental variables as below in script



JENKINS_HOME="/data/jenkins"
JENKINS_WAR="/data/jenkins/jenkins.war"



and passed them to Java with -D option



java -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR



# ps -ef | grep java
root 5 1 0 Mar19 ? 00:05:10 /apps/java/jdk1.8.0_121/bin/java -DJENKINS_HOME=/data/jenkins -jar /data/jenkins/jenkins.war





share|improve this answer






























    0














    The Jenkins wiki discusses setting it up as a Unix daemon: Installing Jenkins as a Unix daemon. You have an RHEL tag in the question, and since RHEL 7 makes use of systemd, you could set up Jenkins to run as a systemd service. The steps to do this are shown below.



    1. First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location /opt/jenkins/jenkins.war.


    2. Next, you'll need to create/prepare the data directory you want to use, which is /data/jenkins.



    3. You can now create a system user account with the name jenkins:



      useradd -r jenkins



    4. Next, change the ownership of the Jenkins WAR file and data directory to this new user:



      chown -R jenkins:jenkins /opt/jenkins/
      chown -R jenkins:jenkins /data/jenkins/



    5. Next, define the systemd service by creating a new unit file:



      vi /etc/systemd/system/jenkins.service

      [Unit]
      Description=Jenkins Daemon

      [Service]
      ExecStart=/bin/java -jar /opt/jenkins/jenkins.war
      User=jenkins
      Environment=JENKINS_HOME=/data/jenkins

      [Install]
      WantedBy=multi-user.target



    6. Make systemd aware of the new unit by reloading it:



      systemctl daemon-reload



    7. Finally, start Jenkins:



      systemctl start jenkins


    You should now be able to access Jenkins on port 8080. If firewalld is active, you'll need to allow the port by running firewall-cmd --add-port=8080/tcp on the system.



    The Jenkins logs can now be seen with journalctl _SYSTEMD_UNIT=jenkins.service. Running ps -ef | grep jenkins will show that it's running as the jenkins user:



    jenkins 1749 1 7 11:04 ? 00:00:35 /bin/java -jar /opt/jenkins/jenkins.war


    As an added bonus, run systemctl enable jenkins if you want the Jenkins service to be automatically started on system boot.






    share|improve this answer






















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507090%2fhow-do-i-run-jenkins-with-a-specific-working-directory-and-a-specific-user-accou%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I used environmental variables as below in script



      JENKINS_HOME="/data/jenkins"
      JENKINS_WAR="/data/jenkins/jenkins.war"



      and passed them to Java with -D option



      java -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR



      # ps -ef | grep java
      root 5 1 0 Mar19 ? 00:05:10 /apps/java/jdk1.8.0_121/bin/java -DJENKINS_HOME=/data/jenkins -jar /data/jenkins/jenkins.war





      share|improve this answer



























        0














        I used environmental variables as below in script



        JENKINS_HOME="/data/jenkins"
        JENKINS_WAR="/data/jenkins/jenkins.war"



        and passed them to Java with -D option



        java -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR



        # ps -ef | grep java
        root 5 1 0 Mar19 ? 00:05:10 /apps/java/jdk1.8.0_121/bin/java -DJENKINS_HOME=/data/jenkins -jar /data/jenkins/jenkins.war





        share|improve this answer

























          0












          0








          0







          I used environmental variables as below in script



          JENKINS_HOME="/data/jenkins"
          JENKINS_WAR="/data/jenkins/jenkins.war"



          and passed them to Java with -D option



          java -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR



          # ps -ef | grep java
          root 5 1 0 Mar19 ? 00:05:10 /apps/java/jdk1.8.0_121/bin/java -DJENKINS_HOME=/data/jenkins -jar /data/jenkins/jenkins.war





          share|improve this answer













          I used environmental variables as below in script



          JENKINS_HOME="/data/jenkins"
          JENKINS_WAR="/data/jenkins/jenkins.war"



          and passed them to Java with -D option



          java -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR



          # ps -ef | grep java
          root 5 1 0 Mar19 ? 00:05:10 /apps/java/jdk1.8.0_121/bin/java -DJENKINS_HOME=/data/jenkins -jar /data/jenkins/jenkins.war






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 22 hours ago









          Zama QuesZama Ques

          94282743




          94282743























              0














              The Jenkins wiki discusses setting it up as a Unix daemon: Installing Jenkins as a Unix daemon. You have an RHEL tag in the question, and since RHEL 7 makes use of systemd, you could set up Jenkins to run as a systemd service. The steps to do this are shown below.



              1. First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location /opt/jenkins/jenkins.war.


              2. Next, you'll need to create/prepare the data directory you want to use, which is /data/jenkins.



              3. You can now create a system user account with the name jenkins:



                useradd -r jenkins



              4. Next, change the ownership of the Jenkins WAR file and data directory to this new user:



                chown -R jenkins:jenkins /opt/jenkins/
                chown -R jenkins:jenkins /data/jenkins/



              5. Next, define the systemd service by creating a new unit file:



                vi /etc/systemd/system/jenkins.service

                [Unit]
                Description=Jenkins Daemon

                [Service]
                ExecStart=/bin/java -jar /opt/jenkins/jenkins.war
                User=jenkins
                Environment=JENKINS_HOME=/data/jenkins

                [Install]
                WantedBy=multi-user.target



              6. Make systemd aware of the new unit by reloading it:



                systemctl daemon-reload



              7. Finally, start Jenkins:



                systemctl start jenkins


              You should now be able to access Jenkins on port 8080. If firewalld is active, you'll need to allow the port by running firewall-cmd --add-port=8080/tcp on the system.



              The Jenkins logs can now be seen with journalctl _SYSTEMD_UNIT=jenkins.service. Running ps -ef | grep jenkins will show that it's running as the jenkins user:



              jenkins 1749 1 7 11:04 ? 00:00:35 /bin/java -jar /opt/jenkins/jenkins.war


              As an added bonus, run systemctl enable jenkins if you want the Jenkins service to be automatically started on system boot.






              share|improve this answer



























                0














                The Jenkins wiki discusses setting it up as a Unix daemon: Installing Jenkins as a Unix daemon. You have an RHEL tag in the question, and since RHEL 7 makes use of systemd, you could set up Jenkins to run as a systemd service. The steps to do this are shown below.



                1. First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location /opt/jenkins/jenkins.war.


                2. Next, you'll need to create/prepare the data directory you want to use, which is /data/jenkins.



                3. You can now create a system user account with the name jenkins:



                  useradd -r jenkins



                4. Next, change the ownership of the Jenkins WAR file and data directory to this new user:



                  chown -R jenkins:jenkins /opt/jenkins/
                  chown -R jenkins:jenkins /data/jenkins/



                5. Next, define the systemd service by creating a new unit file:



                  vi /etc/systemd/system/jenkins.service

                  [Unit]
                  Description=Jenkins Daemon

                  [Service]
                  ExecStart=/bin/java -jar /opt/jenkins/jenkins.war
                  User=jenkins
                  Environment=JENKINS_HOME=/data/jenkins

                  [Install]
                  WantedBy=multi-user.target



                6. Make systemd aware of the new unit by reloading it:



                  systemctl daemon-reload



                7. Finally, start Jenkins:



                  systemctl start jenkins


                You should now be able to access Jenkins on port 8080. If firewalld is active, you'll need to allow the port by running firewall-cmd --add-port=8080/tcp on the system.



                The Jenkins logs can now be seen with journalctl _SYSTEMD_UNIT=jenkins.service. Running ps -ef | grep jenkins will show that it's running as the jenkins user:



                jenkins 1749 1 7 11:04 ? 00:00:35 /bin/java -jar /opt/jenkins/jenkins.war


                As an added bonus, run systemctl enable jenkins if you want the Jenkins service to be automatically started on system boot.






                share|improve this answer

























                  0












                  0








                  0







                  The Jenkins wiki discusses setting it up as a Unix daemon: Installing Jenkins as a Unix daemon. You have an RHEL tag in the question, and since RHEL 7 makes use of systemd, you could set up Jenkins to run as a systemd service. The steps to do this are shown below.



                  1. First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location /opt/jenkins/jenkins.war.


                  2. Next, you'll need to create/prepare the data directory you want to use, which is /data/jenkins.



                  3. You can now create a system user account with the name jenkins:



                    useradd -r jenkins



                  4. Next, change the ownership of the Jenkins WAR file and data directory to this new user:



                    chown -R jenkins:jenkins /opt/jenkins/
                    chown -R jenkins:jenkins /data/jenkins/



                  5. Next, define the systemd service by creating a new unit file:



                    vi /etc/systemd/system/jenkins.service

                    [Unit]
                    Description=Jenkins Daemon

                    [Service]
                    ExecStart=/bin/java -jar /opt/jenkins/jenkins.war
                    User=jenkins
                    Environment=JENKINS_HOME=/data/jenkins

                    [Install]
                    WantedBy=multi-user.target



                  6. Make systemd aware of the new unit by reloading it:



                    systemctl daemon-reload



                  7. Finally, start Jenkins:



                    systemctl start jenkins


                  You should now be able to access Jenkins on port 8080. If firewalld is active, you'll need to allow the port by running firewall-cmd --add-port=8080/tcp on the system.



                  The Jenkins logs can now be seen with journalctl _SYSTEMD_UNIT=jenkins.service. Running ps -ef | grep jenkins will show that it's running as the jenkins user:



                  jenkins 1749 1 7 11:04 ? 00:00:35 /bin/java -jar /opt/jenkins/jenkins.war


                  As an added bonus, run systemctl enable jenkins if you want the Jenkins service to be automatically started on system boot.






                  share|improve this answer













                  The Jenkins wiki discusses setting it up as a Unix daemon: Installing Jenkins as a Unix daemon. You have an RHEL tag in the question, and since RHEL 7 makes use of systemd, you could set up Jenkins to run as a systemd service. The steps to do this are shown below.



                  1. First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location /opt/jenkins/jenkins.war.


                  2. Next, you'll need to create/prepare the data directory you want to use, which is /data/jenkins.



                  3. You can now create a system user account with the name jenkins:



                    useradd -r jenkins



                  4. Next, change the ownership of the Jenkins WAR file and data directory to this new user:



                    chown -R jenkins:jenkins /opt/jenkins/
                    chown -R jenkins:jenkins /data/jenkins/



                  5. Next, define the systemd service by creating a new unit file:



                    vi /etc/systemd/system/jenkins.service

                    [Unit]
                    Description=Jenkins Daemon

                    [Service]
                    ExecStart=/bin/java -jar /opt/jenkins/jenkins.war
                    User=jenkins
                    Environment=JENKINS_HOME=/data/jenkins

                    [Install]
                    WantedBy=multi-user.target



                  6. Make systemd aware of the new unit by reloading it:



                    systemctl daemon-reload



                  7. Finally, start Jenkins:



                    systemctl start jenkins


                  You should now be able to access Jenkins on port 8080. If firewalld is active, you'll need to allow the port by running firewall-cmd --add-port=8080/tcp on the system.



                  The Jenkins logs can now be seen with journalctl _SYSTEMD_UNIT=jenkins.service. Running ps -ef | grep jenkins will show that it's running as the jenkins user:



                  jenkins 1749 1 7 11:04 ? 00:00:35 /bin/java -jar /opt/jenkins/jenkins.war


                  As an added bonus, run systemctl enable jenkins if you want the Jenkins service to be automatically started on system boot.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 20 hours ago









                  HaxielHaxiel

                  3,35511021




                  3,35511021



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507090%2fhow-do-i-run-jenkins-with-a-specific-working-directory-and-a-specific-user-accou%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      oJtq0UP27zr,qP qrq,jlA5Cd YcoQxSR3TYQJzng D0LF,u4Ez2,FN,ZQDSpcBvF L jLzzY7d9S apWUBg9N,zD
                      Pzb0vO,nf4v1BYX,wi1iFsHNb7q2g8 hbqEoP,DZE9JGTZg

                      Popular posts from this blog

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      NetworkManager fails with “Could not find source connection”Trouble connecting to VPN using network-manager, while command line worksHow can I be notified about state changes to a VPN adapterBacktrack 5 R3 - Refuses to connect to VPNFeed all traffic through OpenVPN for a specific network namespace onlyRun daemon on startup in Debian once openvpn connection establishedpfsense tcp connection between openvpn and lan is brokenInternet connection problem with web browsers onlyWhy does NetworkManager explicitly support tun/tap devices?Browser issues with VPNTwo IP addresses assigned to the same network card - OpenVPN issues?Cannot connect to WiFi with nmcli, although secrets are provided

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.