声明性jenkins管道在输入时不中止

声明性jenkins管道在输入时不中止,jenkins,jenkins-pipeline,jenkins-groovy,jenkins-declarative-pipeline,Jenkins,Jenkins Pipeline,Jenkins Groovy,Jenkins Declarative Pipeline,我在jenkins的声明性管道中得到了一个简单的问题。当我在提示符下单击abort时,我不希望它将build标记为aborted。为了防止堆栈已经有了答案,我正在声明式管道中寻找解决方案,而不必转义到脚本 options { timeout(time: 1, unit: 'HOURS') } steps { input 'Deploy to UAT?' deploy() } post { aborted { script { //

我在jenkins的声明性管道中得到了一个简单的问题。当我在提示符下单击abort时,我不希望它将build标记为aborted。为了防止堆栈已经有了答案,我正在声明式管道中寻找解决方案,而不必转义到脚本


 options {
    timeout(time: 1, unit: 'HOURS')
 }

 steps {
   input 'Deploy to UAT?'
   deploy()
 }

 post {
   aborted {
     script {
       //Throws exception(not allowed to use rawBuild)
       currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
       //Do not change status because it can only be worse
       currentBuild.result = 'SUCCESS'
       //Do not change status because it can only be worse
       currentBuild.currentResult = 'SUCCESS'
     }
   }
 }

好吧,你可以

script {
    try {
        input 'Deploy to UAT?'
    } catch(err) {
       currentBuild.result = 'SUCCESS'
       return
    }
}
我想以上是唯一正确的方法


我认为不可能不使用简单的输入字段中止管道,因为这就是它的用途

您可以在输入框中使用复选框,如


def deployToUat
steps {
    script {
        deployToUat = input(
                id: 'Proceed', message: 'Deploy to UAT?', parameters: [
                [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Proceed with deployment?']
        ])
    }
}

stage('UAT deployment') {
    when {
        expression { deployToUat == true }
    }
    steps {
        deploy()
    }
}

首先,声明性管道中没有try/catch,第二,如果您阅读注释,那么以这种方式设置结果在声明性管道中不起作用,我假设您知道解决方法。更新了我的答案。另外,随机给那些想要帮助落选的人也会感到虐待。更不用说看到你得到的异常情况也会有帮助。这就是问题所在,我正在寻找“合适的”解决方案,而不是脚本的变通方法。我找不到任何东西,您的答案和堆栈上的许多主题相同,其中没有一个回答我的问题,是不是可以在声明性管道中完成,而不是直接编写脚本。若你们给出的答案是我在堆栈中已经找到的,那个么我不认为这是滥用。等一下,你们想处理输入的中止,这是上面提供的;)此外,您已经在使用
脚本

def deployToUat
steps {
    script {
        deployToUat = input(
                id: 'Proceed', message: 'Deploy to UAT?', parameters: [
                [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Proceed with deployment?']
        ])
    }
}

stage('UAT deployment') {
    when {
        expression { deployToUat == true }
    }
    steps {
        deploy()
    }
}