Clean way of launching a shell script in background from Jenkins
What's the proper way to launch a script from jenkins, don't get the build hanging, and leave the process running? I can't seem to get it to work. Either the script doesn't run or the build hangs.
If I put in the build's "Execute shell" step bash relaunch.sh & or relaunch.sh > output.log & or nohup bash relaunch.sh &,
nothing happens; build finishes, but the process doesn't run. I guess it can be related to Jenkins waiting for the error pipe to close.
If I do
nohup bash relaunch.sh 2>&1 > output.log as suggested here, the output is properly redirected, but the build hangs (doesn't finish), and the process dies when I kill the build.
Adding export BUILD_ID=dontKillMe, as suggested here, here, and here, either to the "Execute shell" step or the script itself doesn't help either. The build hangs and the process dies when I kill the build. Needless to say, my knowledge of linux is very limited.
How do people do this in a clean way?
linux bash shell jenkins
add a comment |
What's the proper way to launch a script from jenkins, don't get the build hanging, and leave the process running? I can't seem to get it to work. Either the script doesn't run or the build hangs.
If I put in the build's "Execute shell" step bash relaunch.sh & or relaunch.sh > output.log & or nohup bash relaunch.sh &,
nothing happens; build finishes, but the process doesn't run. I guess it can be related to Jenkins waiting for the error pipe to close.
If I do
nohup bash relaunch.sh 2>&1 > output.log as suggested here, the output is properly redirected, but the build hangs (doesn't finish), and the process dies when I kill the build.
Adding export BUILD_ID=dontKillMe, as suggested here, here, and here, either to the "Execute shell" step or the script itself doesn't help either. The build hangs and the process dies when I kill the build. Needless to say, my knowledge of linux is very limited.
How do people do this in a clean way?
linux bash shell jenkins
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37
add a comment |
What's the proper way to launch a script from jenkins, don't get the build hanging, and leave the process running? I can't seem to get it to work. Either the script doesn't run or the build hangs.
If I put in the build's "Execute shell" step bash relaunch.sh & or relaunch.sh > output.log & or nohup bash relaunch.sh &,
nothing happens; build finishes, but the process doesn't run. I guess it can be related to Jenkins waiting for the error pipe to close.
If I do
nohup bash relaunch.sh 2>&1 > output.log as suggested here, the output is properly redirected, but the build hangs (doesn't finish), and the process dies when I kill the build.
Adding export BUILD_ID=dontKillMe, as suggested here, here, and here, either to the "Execute shell" step or the script itself doesn't help either. The build hangs and the process dies when I kill the build. Needless to say, my knowledge of linux is very limited.
How do people do this in a clean way?
linux bash shell jenkins
What's the proper way to launch a script from jenkins, don't get the build hanging, and leave the process running? I can't seem to get it to work. Either the script doesn't run or the build hangs.
If I put in the build's "Execute shell" step bash relaunch.sh & or relaunch.sh > output.log & or nohup bash relaunch.sh &,
nothing happens; build finishes, but the process doesn't run. I guess it can be related to Jenkins waiting for the error pipe to close.
If I do
nohup bash relaunch.sh 2>&1 > output.log as suggested here, the output is properly redirected, but the build hangs (doesn't finish), and the process dies when I kill the build.
Adding export BUILD_ID=dontKillMe, as suggested here, here, and here, either to the "Execute shell" step or the script itself doesn't help either. The build hangs and the process dies when I kill the build. Needless to say, my knowledge of linux is very limited.
How do people do this in a clean way?
linux bash shell jenkins
linux bash shell jenkins
edited May 23 '17 at 12:10
Community♦
11
11
asked May 11 '16 at 10:49
garci560garci560
9411726
9411726
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37
add a comment |
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37
add a comment |
2 Answers
2
active
oldest
votes
A convenient way to achieve that is to change the environment variable BUILD_ID under Execute shell which Jenkins's ProcessTreeKiller is looking for.
By doing,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE as
JENKINS_NODE_COOKIE=dontKillMe
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
If this doesn't work, try settingJENKINS_NODE_COOKIE=dontKillMeinstead - devops.stackexchange.com/questions/1473/…
– Joshua
Feb 13 '18 at 17:56
add a comment |
I was having the exact same problem.
I ended up fixing this by placing the following in the Jenkins execute shell box:
BUILD_ID=dontKillMe ./grid.sh
I moved the & inside the script file. Here's what the script looks like:
#!/bin/bash
java -jar selenium-server-standalone-3.0.1.jar -role hub &
Hopefully this helps someone!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f37160402%2fclean-way-of-launching-a-shell-script-in-background-from-jenkins%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
A convenient way to achieve that is to change the environment variable BUILD_ID under Execute shell which Jenkins's ProcessTreeKiller is looking for.
By doing,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE as
JENKINS_NODE_COOKIE=dontKillMe
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
If this doesn't work, try settingJENKINS_NODE_COOKIE=dontKillMeinstead - devops.stackexchange.com/questions/1473/…
– Joshua
Feb 13 '18 at 17:56
add a comment |
A convenient way to achieve that is to change the environment variable BUILD_ID under Execute shell which Jenkins's ProcessTreeKiller is looking for.
By doing,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE as
JENKINS_NODE_COOKIE=dontKillMe
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
If this doesn't work, try settingJENKINS_NODE_COOKIE=dontKillMeinstead - devops.stackexchange.com/questions/1473/…
– Joshua
Feb 13 '18 at 17:56
add a comment |
A convenient way to achieve that is to change the environment variable BUILD_ID under Execute shell which Jenkins's ProcessTreeKiller is looking for.
By doing,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE as
JENKINS_NODE_COOKIE=dontKillMe
A convenient way to achieve that is to change the environment variable BUILD_ID under Execute shell which Jenkins's ProcessTreeKiller is looking for.
By doing,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE as
JENKINS_NODE_COOKIE=dontKillMe
edited Feb 13 '18 at 17:59
answered May 11 '16 at 11:16
InianInian
39.1k63871
39.1k63871
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
If this doesn't work, try settingJENKINS_NODE_COOKIE=dontKillMeinstead - devops.stackexchange.com/questions/1473/…
– Joshua
Feb 13 '18 at 17:56
add a comment |
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
If this doesn't work, try settingJENKINS_NODE_COOKIE=dontKillMeinstead - devops.stackexchange.com/questions/1473/…
– Joshua
Feb 13 '18 at 17:56
2
2
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
Thanks, this helped us tremendously today!
– Cedric Meury
Mar 13 '17 at 18:01
2
2
If this doesn't work, try setting
JENKINS_NODE_COOKIE=dontKillMe instead - devops.stackexchange.com/questions/1473/…– Joshua
Feb 13 '18 at 17:56
If this doesn't work, try setting
JENKINS_NODE_COOKIE=dontKillMe instead - devops.stackexchange.com/questions/1473/…– Joshua
Feb 13 '18 at 17:56
add a comment |
I was having the exact same problem.
I ended up fixing this by placing the following in the Jenkins execute shell box:
BUILD_ID=dontKillMe ./grid.sh
I moved the & inside the script file. Here's what the script looks like:
#!/bin/bash
java -jar selenium-server-standalone-3.0.1.jar -role hub &
Hopefully this helps someone!
add a comment |
I was having the exact same problem.
I ended up fixing this by placing the following in the Jenkins execute shell box:
BUILD_ID=dontKillMe ./grid.sh
I moved the & inside the script file. Here's what the script looks like:
#!/bin/bash
java -jar selenium-server-standalone-3.0.1.jar -role hub &
Hopefully this helps someone!
add a comment |
I was having the exact same problem.
I ended up fixing this by placing the following in the Jenkins execute shell box:
BUILD_ID=dontKillMe ./grid.sh
I moved the & inside the script file. Here's what the script looks like:
#!/bin/bash
java -jar selenium-server-standalone-3.0.1.jar -role hub &
Hopefully this helps someone!
I was having the exact same problem.
I ended up fixing this by placing the following in the Jenkins execute shell box:
BUILD_ID=dontKillMe ./grid.sh
I moved the & inside the script file. Here's what the script looks like:
#!/bin/bash
java -jar selenium-server-standalone-3.0.1.jar -role hub &
Hopefully this helps someone!
answered Nov 9 '16 at 19:52
user2671131user2671131
10027
10027
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f37160402%2fclean-way-of-launching-a-shell-script-in-background-from-jenkins%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
I'm nominating for reopen, the answers to this question are correct and the duplicate has none of the correct information
– Anthony Sottile
Oct 29 '18 at 19:37