2017-04-05 54 views
1

我在玩詹金斯管道,我在捕获输入步骤的结果时遇到了一些问题。当我声明输入步骤如下...捕获詹金斯输入步骤的结果

stage('approval'){ 
    steps{ 
    input(id: 'Proceed1', message: 'Was this successful?', 
    parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) 
    } 
} 

......一切似乎工作正常。但是,只要我尝试从捕获中获得结果(即给出问题的答案),脚本就不起作用。例如,像下面的脚本:

pipeline { 
    agent { label 'master' } 
    stages { 
    stage('approval'){ 
     steps{ 
      def result=input(id: 'Proceed1', message: 'Was this successful?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) 
      echo 'echo Se ha obtenido aprobacion! (como usar los datos capturados?)' 
     } 
    } 
    } 
} 

...导致以下错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 
WorkflowScript: 6: Expected a step @ line 6, column 13. 
       result=input(id: 'Proceed1', message: 'Was this successful?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) 
      ^

1 error 

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) 
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073) 
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) 
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) 
    ... 
    at hudson.model.Executor.run(Executor.java:404) 
Finished: FAILURE 

的东西很有意思的是,如果我移动的管道{}外部的输入,它的工作原理非常好。我注意到'def'语句发生了相同的行为(我可以在pipeline {}之外定义和使用一个变量,但是我不能在里面定义它)。

我想我必须在这里错过一些非常基本的东西,但经过几个小时尝试不同的配置,我无法设法使其工作。仅仅是在pipeline {}中使用的逻辑仅限于很少的命令?人们如何构建复杂的管道?

任何帮助将不胜感激。

回答

1

我终于设法使它工作,但我不得不彻底改变语法以避免管道,阶段&步骤标记如上面使用。相反,我实现的是这样的:

#!/usr/bin/env groovy 

node('master'){ 

    // -------------------------------------------- 
    // Approval 
    // ------------------------------------------- 
    stage 'Approval' 

    def result=input(id: 'Proceed1', message: 'Was this successful?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) 
    echo 'Se ha obtenido aprobacion! '+result 

} 
2

脚本块允许使用脚本语法管道又名几乎所有的声明式管道内的Groovy的功能。 有关声明式管道的语法比较和限制,请参阅https://jenkins.io/doc/book/pipeline/syntax/

pipeline { 
    agent any 
    ... 
    stages {  
     stage("Stage with input") { 
      steps { 
       script { 
        def result = input(id: 'Proceed1', message: 'Was this successful?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) 
        echo 'result: ' + result 
       }  
      } 
     } 
    } 
} 
相关问题