本文介绍了声明式詹金斯管道完成阶段后如何保持流程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pipeline {
  agent none
  stages {
   stage('Server') {
      agent{
          node {
            label "xxx"
            customWorkspace "/home/xxx/server"
          }
        }
      
      steps {
        sh 'node server.js &'
        //start server
      }
    }
   stage('RunCase') {
      agent{
          node {
            label 'clientServer'
            customWorkspace "/home/xxx/CITest"
          }
        }

      steps{
        sh 'start test'
        sh  'run case here'
      }
    }
  }

}

我在Jenkins管道上方创建.我想做的是:
1.在服务器节点上启动服务器.
2.在测试节点上开始测试.

I create above Jenkins pipeline. What I want to do is:
1. start server at server node.
2. start test at test node.

但是,我发现第二阶段启动时服务器进程将关闭.因此,如何在第二阶段测试工作完成之前保持服务器启动.我尝试使用&,但仍然无法正常工作.看来这将扼杀我在第一阶段开始的所有过程.

However, I found the server process will be closed when second stage start.So how to keep server start until my second stage testing work is finished. I try to use &, still not working. It seems it will kill all process I started at first stage.

推荐答案

一种解决方案是尝试以并行"模式启动两个阶段.有关更多信息,请参见以下两个文件: parallel-declarative-blog jenkins-pipeline-syntax .但是要小心,因为不能保证第一阶段要在第二阶段开始之前开始.也许您需要等待时间才能进行测试.这是一个Jenkinsfile示例:

One solution is to try to start the two stages in "parallel"-mode. For more informations see this two files: parallel-declarative-blog jenkins-pipeline-syntax. But be carefull, because it is not ensured, that the first stage starts before the second one starts. Maybe you need a waiting time for your tests. Here is an example Jenkinsfile:

pipeline {
agent none
stages {
    stage('Run Tests') {
        parallel {
            stage('Start Server') {
                steps {
                    sh 'node server.js &'
                }
            }
            stage('Run Tests) {
                steps {
                    sh  'run case here'
                }
            }
        }
    }
}
}

另一种解决方案是在后台启动节点服务器.为此,您可以尝试其他工具,例如 nohup pm2 .

Another solution would be to start the node server in the background. For this you can try different tools, like nohup or pm2.

这篇关于声明式詹金斯管道完成阶段后如何保持流程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:29