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












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
    20 hours ago











  • Also, did you create /data dir?

    – nwildner
    17 hours ago
















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
    20 hours ago











  • Also, did you create /data dir?

    – nwildner
    17 hours ago














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 11 mins ago









Haxiel

3,32511020




3,32511020










asked yesterday









Zama QuesZama Ques

94282743




94282743













  • Did you create the user jenkins?

    – Panki
    20 hours ago











  • Also, did you create /data dir?

    – nwildner
    17 hours ago



















  • Did you create the user jenkins?

    – Panki
    20 hours ago











  • Also, did you create /data dir?

    – nwildner
    17 hours ago

















Did you create the user jenkins?

– Panki
20 hours ago





Did you create the user jenkins?

– Panki
20 hours ago













Also, did you create /data dir?

– nwildner
17 hours ago





Also, did you create /data dir?

– nwildner
17 hours ago










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 1 hour 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 13 mins ago









                  HaxielHaxiel

                  3,32511020




                  3,32511020






























                      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







                      Popular posts from this blog

                      CARDNET

                      Boot-repair Failure: Unable to locate package grub-common:i386

                      濃尾地震