简体   繁体   English

如何使用 GitLab runner 运行 spring-boot 应用程序?

[英]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 the build , test and deploy are allowed to be used as job's stage by default.如果没有stages定义在.gitlab-ci.yml ,那么buildtestdeploy允许被用作默认作业的阶段。 (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.

相关问题 如何将spring-boot作为客户端应用程序运行? - How to run spring-boot as a client application? 在 Liberty Server 上运行 spring-boot 应用程序 - Run spring-boot application on Liberty Server Spring-Boot 应用程序使用 VScode 运行配置 - Spring-Boot application run configurations with VScode 在spring-boot中,如何使用应用程序属性记录MDC? - In spring-boot, how to log MDC using application properties? 如何使用 Swing 应用程序配置 spring-boot - How to configure spring-boot with swing application 使用 maven “命令”在同一项目中运行 spring-boot 应用程序及其 cucumber 测试 - Run a spring-boot application and its cucumber tests in the same project using one maven “command” Spring-boot项目给出“应用程序运行失败”错误 - Spring-boot project giving “Application run failed” error spring-boot,maven:无法运行或打包应用程序 - spring-boot, maven: failing to run or package an application 在现有的 spring-boot 应用程序中,在单独的线程中运行无限循环 - In a existing spring-boot application, run a infinite loop in a seperate thread Spring-boot:在不启动应用程序的情况下运行 flyway 迁移 - Spring-boot: Run flyway migration without starting application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM