2017-04-05 48 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 
       }  
      } 
     } 
    } 
} 
相關問題