如何在 jenkins 中启动服务器以并行 运行 验收测试?

How to start up a server in jenkins to run acceptance tests in parallel?

作为构建的一部分,这些是我的阶段:

  1. 编译打包项目
  2. 并行作业:
    • 运行 单元测试
    • 通过执行阶段 1 中创建的 jar 文件启动服务器
    • 等待服务器准备就绪并运行验收测试 反对

问题是当验收测试完成后,我如何通知其他并行作业关闭服务器?目前,即使我从 Jenkins 中终止构建,jar 执行过程仍保持 运行ning。

此外,如果构建被手动取消,我们如何捕获该事件并使用脚本 pipeline/groovy 向服务器发出关闭自身的信号?

示例代码:

node('jenkins-jenkins-slave') {

    stage('Parallel jobs') {
        parallel 
        stage('Preparing server for acceptance test') {
            script {

                def propertiesString = ''
                def jvmOptions = ''

                def properties = readProperties file: "${propertiesFile}".toString()
                properties.each { k, v ->
                    propertiesString = propertiesString + "-D${k}=${v} ".toString()
                }

                sh "java ${jvmOptions} -Dloader.path=${loaderPath} ${propertiesString}-jar ${jarFile} --spring.profiles.active=${activeProfiles}"
            }
        },
        stage('Acceptance tests') {
            script {
                def scriptName = 'wait_until_env_ready.sh'
                def exists = fileExists "$scriptName"
                if(!exists) {
                    def scriptContent = libraryResource "${scriptName}"
                    writeFile file: "${scriptName}", text: scriptContent
                    sh "chmod +x ${scriptName}"
                }
                sh "./wait_until_env_ready.sh http://localhost:8090/manage/health"
                sh "mvn -B test -Dmaven.repo.local=/root/.m2/repository -DskipTests=true -DskipITs=false"
                // How to signal the above stage to shut down the jar execution?
            }
        }       
    }
}

您要找的是post-always -section

您还需要一些方法来终止服务器。例如在 post.

中找到它的 PID 和 kill