[英]How to run spring-boot application using GitLab runner?
I have a spring-boot maven application I've been running locally as:我有一个在本地运行的 spring-boot maven 应用程序:
mvn spring-boot:run
I want to be able to run this in GitLab runner so that when I push the code to master, it automatically copies the latest up there and runs the application.我希望能够在 GitLab runner 中运行它,这样当我将代码推送到 master 时,它会自动复制最新的代码并运行应用程序。
My GitLab runner is configured in shell mode right now, and I have inside of the .gitlab-ci.yml
file a deploy task that runs just that:我的 GitLab 运行器现在配置为 shell 模式,并且我在.gitlab-ci.yml
文件中有一个运行的部署任务:
mvn spring-boot:run
The issue I am running into is after the application starts, I can see that it is running... but it never shows as success or completed.我遇到的问题是在应用程序启动后,我可以看到它正在运行……但它从未显示为成功或完成。 It just hangs there (because the terminal is still running when you execute that command?)它只是挂在那里(因为执行该命令时终端仍在运行?)
Question is, is there an alternate set of commands I should be running to get my spring-boot application to update and run each time I push to master?问题是,每次我推送到 master 时,是否应该运行一组备用命令来更新和运行 spring-boot 应用程序? What is it i should be putting into my gitlab-ci.yml
(or other files).我应该将什么放入我的gitlab-ci.yml
(或其他文件)中。 Note that I am not using docker or kubernetes... just shell.请注意,我没有使用 docker 或 kubernetes ......只是shell。
Sample gitlab CI:示例 gitlab CI:
run-deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS spring-boot:run
Trying nohup with that also fails.尝试使用 nohup 也失败了。 - nohup mvn $MAVEN_CLI_OPTS spring-boot:run &
I believe you can use the run
stage for this.我相信您可以为此使用run
阶段。 It would look something like它看起来像
run:
stage: run
script:
- mvn $MAVEN_CLI_OPTS spring-boot:run
You can see an example of this here .你可以在这里看到一个例子。
Make sure you also define the stages
to include run
as the docs state确保您还定义了包含run
as the docs state 的stages
If no
stages
are defined in.gitlab-ci.yml
, then thebuild
,test
anddeploy
are allowed to be used as job's stage by default.如果没有stages
定义在.gitlab-ci.yml
,那么build
,test
和deploy
允许被用作默认作业的阶段。 (see stages ) (见阶段)
Is the sample file you provided above your entire configuration file or only a snippet of it?您在整个配置文件上方提供的示例文件还是其中的一部分? If so, I can adjust my answer to fit your needs.如果是这样,我可以调整我的答案以满足您的需求。 Thanks!谢谢!
I'm sorry this is so late.我很抱歉这么晚了。 I've recently just had the same problem.我最近刚遇到同样的问题。 Gitlab runner blocks on child processes, and any process in the child tree. Gitlab 运行块在子进程和子树中的任何进程上。 This makes the disown
command impossible since you can't get to it.这使得disown
命令变得不可能,因为您无法使用它。 Forking, and nohup
also don't work. Forking 和nohup
也不起作用。
The only solution I could figure out was using the at
command https://linux.die.net/man/1/at我能找到的唯一解决方案是使用at
命令https://linux.die.net/man/1/at
Basically I put my command in a script then did:基本上我把我的命令放在一个脚本中然后做了:
at now < my_blocking_command_script.sh
That successfully complete the runner and kicked off my program in the background.这成功地完成了跑步者并在后台启动了我的程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.