状态为“已暂停”时,Jenkins Pipeline发布操作sshPublisher无法正常工作

时间:2018-10-02 11:37:54

标签: jenkins continuous-integration pipeline

在Jenkins文件中,使用always的帖子块sshPublisher似乎对我来说很麻烦。如果构建状态为ABORTED,则不会执行该操作。

假设我有以下Jenkinsfile

pipeline {
    agent any
    environment {
        // setup
    }
    stages {
        stage("Build") {
            // build
        }
        stage("Deploying for review") {
            steps {
                sshPublisher(publishers: [sshPublisherDesc(configName: "foo", transfers: [
                    sshTransfer(execCommand: "docker run --rm -d -p $PORT:443 " +
                        " --name '$PROJECT-$DOCKER_TAG' bar.foo.com/$PROJECT:$DOCKER_TAG")
                ])])
            }
        }
        stage("Review") {
            agent none
            steps {
                input "Deploy to production?"
            }
        }
        stage("Promotion") {
            steps {
                echo "Promotion"
            }
        }
        stage("Deploying to production") {
            steps {
                echo "Deploy to production"
            }
        }
    }
    post {
        always {
            sshPublisher(publishers: [sshPublisherDesc(configName: "foo", transfers: [
                sshTransfer(execCommand: "docker stop '$PROJECT-$DOCKER_TAG')
            ])])
        }
    }
}

如果用户在Review阶段中止构建,则将生成以下输出,并且不会执行docker stop块中的post命令。

[Pipeline] stage
[Pipeline] { (Review)
[Pipeline] {
[Pipeline] input
Deploy to production?
Proceed or Abort
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Promotion)
Stage "Promotion" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploying to production)
Stage "Deploying to production" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] step
SSH: Current build result is [ABORTED], not going to run.
[Pipeline] }
[Pipeline] // stage

首先,如果构建结果为sshPublisher,为什么不执行ABORTED?而且,如果有正当的理由,我该如何强制其继续运行?

0 个答案:

没有答案