繁体   English   中英

完成 Jenkins 构建管道,但保持 Java/Maven 应用程序运行

[英]Finish a Jenkins build pipeline but leave Java/Maven app running

我有一个小项目分配给我,有一个特定的用例和很短的时间 window。 I have to run Jenkins on a Windows 2019 Server VM instance in Google Cloud, clone a spring boot/Maven application from GitHub, build, test, and run the application. 这是我第一次使用 Jenkins 和 spring 启动/Maven,所以我有点卡在如何进步。

我的仓库中有一个 Jenkinsfile 并已成功克隆、构建、测试和运行应用程序,唯一的问题是在构建的“运行”阶段,它无限期地运行,直到我手动中止构建。 有没有办法完成管道构建但让应用程序继续运行? 下面是我的 Jenkinsfile。

    pipeline {
  agent any
  stages {
    stage("Clean Up"){
      steps{
        deleteDir()
      }
    }
    stage("Clone Repo"){
      steps {
        bat "git clone https://github.com/CBoton/spring-boot-hello-world.git"
      }
    }
    stage("Build"){
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn clean install"
        }
      }
    }
    stage("Test") {
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn test"
        }
      }
    }
    stage("Run") {
        steps {
          dir("spring-boot-hello-world") {
            bat "mvn spring-boot:run"
        }
      }
    }
  }
}

在此先感谢您的任何建议。

干杯

您希望在后台启动Run阶段的进程,以便 Jenkins 管道可以在后台进程仍在运行时继续/终止。

如果它是 Linux,则 Bash 将支持在后台运行进程,方法是用&结束命令,最终由 nohup 支持,以确保它在管道(父作业)被终止时不会被终止。 https://www.maketecheasier.com/run-bash-commands-background-linux/中有更详细的解释。

在我看来,您正在 Windows 中运行所有这些。 这里的start命令似乎可以完成这项工作。 请参阅如何在 Windows 的后台运行命令?

在我看来,像您一样运行该服务意味着它没有纠错。 如果它失败了,系统和你都不会注意到,更不用说在失败或系统重启后自动启动服务了。 尝试将其作为服务运行。 这意味着您的管道会将其安装为服务,然后启动该服务。 服务控制管理器将监视并确保命令正在运行并继续运行。 在这种情况下, Procrun 之类的工具可以为您提供帮助。

暂无
暂无

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

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