【问题标题】:how to keep process running after the stage is finished for declarative jenkins pipeline如何在声明式詹金斯管道的阶段完成后保持进程运行
【发布时间】:2023-03-16 06:53:01
【问题描述】:

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. 在测试节点开始测试。

但是,我发现第二阶段启动时服务器进程将关闭。 那么如何保持服务器启动直到我的第二阶段测试工作完成。我尝试使用&,仍然无法正常工作。似乎它会杀死我在第一阶段开始的所有过程。

【问题讨论】:

    标签: jenkins-pipeline


    【解决方案1】:

    一种解决方案是尝试以“并行”模式启动两个阶段。有关更多信息,请参阅这两个文件:parallel-declarative-blogjenkins-pipeline-syntax。但要小心,因为不能保证第一阶段在第二阶段开始之前开始。也许您需要等待测试的时间。这是一个 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'
                    }
                }
            }
        }
    }
    }
    

    另一种解决方案是在后台启动节点服务器。为此,您可以尝试不同的工具,例如 nohuppm2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 2016-10-08
      相关资源
      最近更新 更多