2017-08-07 83 views
0

我有一個管道腳本,看起來像這樣:如何使用jenkins中的不同參數運行相同的管道?

node { 
    try { 
    stage('Prepare') { 
     // git clone here 
    } 
    stage('Compile') { 
     sh "make ${build_type}" 
    } 
    stage('Test') { 
     sh "./run tests ${build_type}" 
    } 
    } 
    finally { 
    if (fileExists("test_results.xml")) { 
     junit "test_results.xml" 
    } 
    emailext subject: "Build finished", 
     body: '${JELLY_SCRIPT, template="some-template.template"}', 
     to: "[email protected]" 
    } 
} 

$ {} build_type可以 「釋放」 或 「調試」。

當我生成接收到觸發,我想我的管道在$ {} build_type每個參數運行一次,然後給我一份報告,關於這兩個構建一個電子郵件。

我該如何做到這一點?

我試圖在Compile階段內定義一個並行塊並在其中設置build_type,但這不會使其他階段並行運行。

回答

1

我希望以下代碼段可以幫助你。這樣你可以包含多個構建類型dev,qa,prod。

def build_types = "dev;qa" 

node { 
try { 
     stage('Prepare') { 
      // git clone here 
     } 

    def buildTypeVar = build_types.tokenize(';') 

    for(int i=0;i<buildTypeVar.size();i++){ 

     buildType=buildTypeVar.get(i).trim() 

     stage('Compile ${build_type}') { 
      sh "make ${build_type}" 
     } 
     stage('Test ${build_type}') { 
      sh "./run tests ${build_type}" 
     } 
    } 

} 
finally { 
    if (fileExists("test_results.xml")) { 
    junit "test_results.xml" 
    } 
    emailext subject: "Build finished", 
    body: '${JELLY_SCRIPT, template="some-template.template"}', 
    to: "[email protected]" 
} 
} 
相關問題