How do I run Jenkins with a specific working directory and a specific user account?
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
add a comment |
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
Did you create the userjenkins
?
– Panki
20 hours ago
Also, did you create/data
dir?
– nwildner
17 hours ago
add a comment |
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
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
rhel java jenkins
edited 11 mins ago
Haxiel
3,32511020
3,32511020
asked yesterday
Zama QuesZama Ques
94282743
94282743
Did you create the userjenkins
?
– Panki
20 hours ago
Also, did you create/data
dir?
– nwildner
17 hours ago
add a comment |
Did you create the userjenkins
?
– 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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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.
First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location
/opt/jenkins/jenkins.war
.Next, you'll need to create/prepare the data directory you want to use, which is
/data/jenkins
.
You can now create a system user account with the name
jenkins
:
useradd -r jenkins
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/
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
Make
systemd
aware of the new unit by reloading it:
systemctl daemon-reload
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered 1 hour ago
Zama QuesZama Ques
94282743
94282743
add a comment |
add a comment |
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.
First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location
/opt/jenkins/jenkins.war
.Next, you'll need to create/prepare the data directory you want to use, which is
/data/jenkins
.
You can now create a system user account with the name
jenkins
:
useradd -r jenkins
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/
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
Make
systemd
aware of the new unit by reloading it:
systemctl daemon-reload
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.
add a comment |
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.
First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location
/opt/jenkins/jenkins.war
.Next, you'll need to create/prepare the data directory you want to use, which is
/data/jenkins
.
You can now create a system user account with the name
jenkins
:
useradd -r jenkins
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/
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
Make
systemd
aware of the new unit by reloading it:
systemctl daemon-reload
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.
add a comment |
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.
First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location
/opt/jenkins/jenkins.war
.Next, you'll need to create/prepare the data directory you want to use, which is
/data/jenkins
.
You can now create a system user account with the name
jenkins
:
useradd -r jenkins
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/
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
Make
systemd
aware of the new unit by reloading it:
systemctl daemon-reload
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.
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.
First, you'll need to download the Jenkins WAR file and place it somewhere. I chose the location
/opt/jenkins/jenkins.war
.Next, you'll need to create/prepare the data directory you want to use, which is
/data/jenkins
.
You can now create a system user account with the name
jenkins
:
useradd -r jenkins
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/
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
Make
systemd
aware of the new unit by reloading it:
systemctl daemon-reload
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.
answered 13 mins ago
HaxielHaxiel
3,32511020
3,32511020
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Did you create the user
jenkins
?– Panki
20 hours ago
Also, did you create
/data
dir?– nwildner
17 hours ago