'Jenkins deployment to Tomcat failed
I'm currently learning and implementing Jenkin's Pipeline for automated integration for java web application.
My plan is that once developers successfully commit and push their codes, Jenkins on admin server check out the code, build the project, stop the currently running Tomcat, deploy the project to the Tomcat, and restart.
For testing purpose, I'm currently trying everything, including running Tomcat and Jenkins, on local machine. But Jenkins is running its own (by executing command "Java -jar jenkins.war") but not using tomcat
Everything worked fine with pipeline except for starting Tomcat. below is the pipeline code snippet for tomcat restart.
stage('Restart') {
steps {
echo 'Restarting Tomcat.....'
sh '''
cd ~/PATH-TO-Tomcat/apache-tomcat-8.0.44/bin
./startup.sh
'''
}
}
As you can see, it simply goes to tomcat directory and execute the startup.sh script. However, when executing the restart stage, only the message "Tomcat started." is recored in console log file, but when checking with local host, Tomcat was not started at all.
I tried to start tomcat manually by executing command using terminal, it works okay.
Please help
Thank you
Solution 1:[1]
I have also encountered this problem when starting shell scripts from Jenkins.
Problem
The problem is that the shell script is started within the scope of the Jenkins build. As soon as the build is stopped it behaves like if you close the terminal which is running the script. Thus, Tomcat is stopped when the Job ends.
Solution (kind of)
Try to start Tomcat in background (How to run a shell script in the background and get no output) which detaches the script from the job. Or you could install your Tomcat as a service (java install tomcat as service) and start the service from Jenkins.
Solution 2:[2]
After starting tomcat use sleep command till the application is up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | arifCee |
Solution 2 | Srilekha Reddy |