如何使用 Jenkins 部署 SpringBoot Maven 应用程序? [英] How to deploy SpringBoot Maven application with Jenkins ?

查看:40
本文介绍了如何使用 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 在评论中建议的解决方法 (nohuping) 并没有改变我的行为,但一个简单的解决方法是使用 schedule 应用程序的启动>at unix 命令:

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 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆