简体   繁体   English

如何在Jenkins上部署我的Spring Boot项目?

[英]How to deploy my Spring Boot project on Jenkins?

I am trying to create a deploy job in Jenkins for my Spring Boot - Maven project. 我正在尝试为我的Spring Boot-Maven项目在Jenkins中创建部署作业。 These are the steps i have followed until now: 这些是我到目前为止所遵循的步骤:

  • Click New Item 点击新项目
  • Give a name, and choose Maven project 命名,然后选择Maven项目
  • Configuration page opens 配置页面打开
  • In Source Code Management, i have given my Git repository URL 在源代码管理中,我给出了我的Git存储库URL
  • In Build section under Goals and options i have written "spring-boot:run" 在“目标和选项”下的“构建”部分中,我编写了“ 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. 由于我没有任何詹金斯经验,因此我需要一个简单的分步指导。

The job doesn't end because your application is up and running on embeeded Tomcat. 作业不会结束,因为您的应用程序已启动并在嵌入式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 (eg 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 ; 填写“源代码管理”:您的存储库URL和凭据,要建立的分支- */master ;
  • Fill 'Build Triggers': select 'Poll SCM' and type H/2 * * * * in 'Shedule' to poll repository every 2 minutes; 填写“构建触发器”:选择“轮询SCM”,然后在“规约”中键入H/2 * * * *每2分钟轮询一次存储库;
  • 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) - 填写“构建”:添加构建步骤“执行外壳”并键入下一个命令以停止当前构建并开始新的构建(不要忘记用您的值替换JENKINS_URL和JOB_NAME)-

     curl -X POST http://JENKINS_URL/job/JOB_NAME/lastBuild/stop; curl -X POST http://JENKINS_URL/job/JOB_NAME/build; 
  • Save your job :) 保存您的工作:)

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 . 我认为,如果要在不同于jenkins服务器的另一台服务器上部署spring-boot应用程序,则需要构建应用程序mvn clean package并将创建的jar从jenkins服务器移动到新服务器,然后可以使用另一步骤使用java -jar myapp.jar启动应用程序。 But, if you are going to deploy in tomcat server then you can use tomcat-api to deploy remotely. 但是,如果要在tomcat服务器中进行部署,则可以使用tomcat-api进行远程部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM