How to deploy my Spring Boot project on Jenkins?

我怕爱的太早我们不能终老 提交于 2019-12-11 03:37:34

问题


I am trying to create a deploy job in Jenkins for my Spring Boot - Maven project. These are the steps i have followed until now:

  • Click New Item
  • Give a name, and choose Maven project
  • Configuration page opens
  • In Source Code Management, i have given my Git repository URL
  • In Build section under Goals and options i have written "spring-boot:run"
  • Saved and applied

Now when i click "Build Now", it checks out the project, builds and deploys. But the job does not end. This is the last line in the console output screen:

: Started Application in 4.737 seconds (JVM running for 16.297)

What is my problem? I need a simple step by step guidance since i do not have any Jenkins experience.

EDIT: I do not know what post build action is which is mentioned in the other post. I need a simple step by step guidance since i do not have any Jenkins experience.


回答1:


The job doesn't end because your application is up and running on embeeded Tomcat. It's normal behaviour and you should be able to use your application at this point.


If you want to make another build, you should stop current build before starting a new one. To do this automaticaly (e.g. when your master branch is changed) you can create another one job.

Example of a job that triggers build of a main job:

  • Create a 'Freestyle project' in Jenkins;
  • Fill 'Source Code Management': your Repository URL and Credentials, Branches to build - */master;
  • Fill 'Build Triggers': select 'Poll SCM' and type H/2 * * * * in 'Shedule' to poll repository every 2 minutes;
  • Fill 'Build': add build step 'Execute shell' and type next commands to stop current build and start a new one (don't forget to replace JENKINS_URL and JOB_NAME with your values) -

    curl -X POST http://JENKINS_URL/job/JOB_NAME/lastBuild/stop;
    curl -X POST http://JENKINS_URL/job/JOB_NAME/build;
    
  • Save your job :)




回答2:


I think that if you are going to deploy the spring-boot application in another server different to jenkins server you need to build your app mvn clean package and to move the jar created from jenkins server to the new server then you can use another step to start the app using java -jar myapp.jar. But, if you are going to deploy in tomcat server then you can use tomcat-api to deploy remotely.



来源:https://stackoverflow.com/questions/30437774/how-to-deploy-my-spring-boot-project-on-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!