本文介绍了如何使用Jenkins部署SpringBoot Maven应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序,该应用程序在嵌入式Tomcat Servlet容器mvn spring-boot:run上运行.而且我不想将项目作为单独的战争部署到独立的Tomcat.

I have a Spring Boot application which runs on embedded Tomcat servlet container mvn spring-boot:run . And I don’t want to deploy the project as separate war to standalone Tomcat.

每当我将代码推送到BitBucket/Github时,钩子就会运行并触发Jenkins作业(在Amazon EC2上运行)来部署应用程序.

Whenever I push code to BitBucket/Github, a hook runs and triggers Jenkins job (runs on Amazon EC2) to deploy the application.

Jenkins作业有一个后构建动作:mvn spring-boot:run,问题是该后构建动作完成后,该作业挂起.

The Jenkins job has a post build action: mvn spring-boot:run, the problem is that the job hangs when post build action finished.

应该有另一种方式来做到这一点.任何帮助将不胜感激.

There should be another way to do this. Any help would be appreciated.

推荐答案

问题是Jenkins . @Steve在注释(nohup ing)中建议的解决方法并没有改变我的情况,但是一个简单的解决方法是使用at unix命令从 schedule 应用程序开始: /p>

The problem is that Jenkins doesn't handle spawning child process from builds very well. Workaround suggested by @Steve in the comment (nohuping) didn't change the behaviour in my case, but a simple workaround was to schedule app's start by using the at unix command:

> echo "mvn spring-boot:run" | at now + 1 minutes

通过这种方式,詹金斯(Jenkins)成功完成了工作,而不会超时.

This way Jenkins successfully completes the job without timing out.

如果最终通过java -jar app.jar.jar文件运行应用程序,请注意引导如果.jar文件被覆盖而中断,则需要在复制工件之前确保应用程序已停止.如果您使用的是ApplicationPidListener,则可以通过添加以下命令的执行来验证应用程序是否正在运行(如果正在运行,则将其停止):

If you end up running your application from a .jar file via java -jar app.jar be aware that Boot breaks if the .jar file is overwritten, you'll need to make sure the application is stopped before copying the artifact. If you're using ApplicationPidListener you can verify that the application is running (and stop it if it is) by adding execution of this command:

> test -f application.pid && xargs kill < application.pid || echo 'App was not running, nothing to stop'

这篇关于如何使用Jenkins部署SpringBoot Maven应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:08