声明管道步骤等待进程完成以便将阶段标记为已完成

时间:2018-03-12 14:04:23

标签: jenkins jenkins-pipeline jenkins-declarative-pipeline

使用声明性管道,我如何根据给定条件标记完成的阶段?

对于以下示例,我想在没有进程运行时将阶段标记为已完成。

此示例将应用于检查软杀死后给定应用程序何时未运行以继续部署

pipeline {
    agent any
    stages {
        stage('1') {
            steps {
                timeout(time: 10, unit: 'MINUTES') {
                    waitUntil {
                        script {
                            def ret = sh script: 'ps ux | grep testout.sh  | grep -v grep | wc -l', returnStdout: true
                            echo ret
                            if (ret != 0) {
                                // what should i use to finish this step?
                            }
                        }                        
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我相信有更好的方法可以做到这一点,但目前我正在实现所需的结果:

pipeline {
    agent any
    stages {
        stage('1') {
            steps {
                timeout(time: 10, unit: 'MINUTES') {
                    script {
                        waitUntil {
                            def ret = sh script: 'ps ux | grep testout.sh  | grep -v grep | wc -l', returnStdout: true
                            if (ret.trim() != "0" ) {
                                return false
                            } else {
                                return true
                            }                            
                        }

                    }
                }

            }
        }
    }
}

与此同时,如果我找到合适的解决方案,我会更新此答案。

相关问题