2017-06-02 81 views

回答

3

你可以把Groovy代碼在一個(總是源控制)Jenkinsfile管道,像這樣:

pipeline { 
    agent { label 'docker' } 
    stages { 
    stage ('build') { 
     steps { 
     script { 

      // i used a script block because you can jam arbitrary groovy in here 
      // without being constrained by the declarative Jenkinsfile DSL 
      def awesomeVar = 'so_true' 
      print "look at this: ${awesomeVar}" 

      // accessing a predefined variable: 
      echo "currentBuild.number: ${currentBuild.number}" 
     } 
     } 
    } 
    } 
} 

可生產控制檯日誌:

[Pipeline] echo 
look at this: so_true 
[Pipeline] echo 
currentBuild.number: 84 

單擊「管道語法「鏈接在任何管道作業的左側導航欄中,以獲取一些您可以在」全局變量參考「中訪問的示例。

+0

我不認爲這種方式的腳本是在主人身上執行的,而是受詹金斯的沙箱模式的約束?我對「Execute system groovy script」的系統部分超級感興趣:-D – C4stor

+0

它在master上執行,它受jenkins的沙盒模式的約束,可以根據每個案例的基本情況重寫方法在https://medium.com/dronzebot/jenkins-groovy-script-approval-eff569f597f6中描述。 – burnettk

+0

好吧,我的壞,偉大然後:) – C4stor

相關問題