I am trying to automate a SpringBoot Application through Jenkins.
I have myApp.jar and currently, I run it using the following command
nohup java -jar myApp.jar &
Press Ctrl^C or Ctrl^Z and process keep running in the background.
Logs will be added in nohup.out
Now I want the same process to be done using Jenkins.
In Jenkins, build section, I have selected Execute Shell Script with the above command.
When build is triggered. I can see Application startup Log in Jenkins Log but the problem is, build never finishes.
I have tried
BUILD_ID=dontKillMe timeout --foreground 30 nohup java -jar website-status.jar &
also
BUILD_ID=dontKillMe nohup java -jar website-status.jar &
timeout is killing the process. I don't want process to be killed.
Edit 1:
I have tried this as well. Build keeps running.
JENKINS_NODE_COOKIE=dontKillMe nohup java -jar website-status.jar &
When we execute command like this
nohup java -jar myApp.jar &
a prompt is shown saying log will be written in nohup.out file and this was causing the script to hang forever in Jenkins.
I changed the command and now no prompt and works fine, logs are written in server.log
nohup java -jar myApp.jar >> server.log 2>&1&
Related
I have deployed my web application on company server by executing jar files then the project is running fine.But when i close the jar and again try to run the project on browser then client is not able to access the application.I want solution on this that if i close the jar then also client can access the application.
you can use this simple command to run a jar file as background service...
javaw -jar test.jar
after run this command you could not detect any change in cmd...and can close your command prompt. after 1 or 2 minute enter your URL in browser .. you will see your web program is running...
before run this command must be stop previously running jar for avoid same port conflict
for more details
When you close the cmd prompt, your java application will also be killed. To keep the java application running after closing the terminal you have to use the below command.
nohup java -jar app_name.jar &
just replace the app_name with your application name and run the command.
I'm running this command manually on console, java -jar agent.jar -jnlpUrl {{master_url}}/computer/{{slave_name}}/slave-agent.jnlp -secret {{secret_key}} > /dev/null 2>&1 &
basically it is starting the jenkins slave in background and it works fine, now when i try to do the same thing in Chef, the chef-client process hangs and gets timed out because process never goes in background and session remains active.
command = Mixlib::ShellOut.new("java -jar agent.jar -jnlpUrl {{master_url}}/computer/{{slave_name}}/slave-agent.jnlp -secret {{secret_key}}" > /dev/null 2>&1 &")
command.run_command
You really should be using a proper service layer for this, which is systemd in all modern Linux distros.
I want to stop and start WebLogic from Jenkins. If I start by shell script in Jenkins:
./startWebLogic.sh
the process is not finished, but WebLogic is started.
If I start by shell script with nohup in Jenkins:
. ./setWLSEnv.sh
nohup ./startWebLogic.sh > /dev/null &
the process is finished, but WebLogic is not started.
I tried the same script on the same server from putty, in result process is finished and WebLogic is started.
How I can start WebLogic and execute other shell script from Jenkins.
It worked for me. But this code has one issue. When you put your process in background you can't see logs of the process. And if your weblogic couldn't start at all you will know that only on the further stages (trying to deploy - in my case).
stage('Start WLS') {
steps {
sh '${DOMAIN_BIN_DIR}/startWebLogic.sh &'
}
}
Hope, someone will give a better solution with ability to determine the fact of Weblogic's fall on the running stage.
is there any way to force Jenkins job to run on foreground?
this is the script I use to start the Job.
cd %LibPath%
java -cp "%LibPath%/*;" STARTJenkins %TestPlanName% %User% %Password% NONE %WORKSPACE%
Issue seems to persist only if user running Jenkins is locked
I want my JBoss server to run in background, for that I am using nohup ./startPID.sh > /dev/null 2>&1& command. But when I pass same command in Jenkins, it doesn't work as expected. The console output in Jenkins says "command ran successfully" but in backend the JBoss server is still down.
Any inputs?
Regards
Manish Mehra
Use "at now" instead of "nohup"
In your job jenkins (execute shell) put :
set +e #so "at now" will run even if java -jar fails
#Run java app in background
echo "java -jar $(ls | grep *.jar | head -n 1)" | at now + 1 min
You could look at the JBoss management plugin
which spins up JBoss for you
This plugin allows to manage a JBoss Application Server during build
procedure.
With the plugin we can start/stop JBoss AS. It's very useful if we
need to run some integration tests against of the server. There is
also operation allows verification if artifacts are deployable.
It looks to be quite an old plugin but has cuurent users