2016-02-05 117 views
1

我試圖使用這個有條件的多步驟插件,併爲DSL編寫了grrovy腳本,但是當我使用這段代碼引導時,列出的步驟在條件塊之前是外部的,我在這裏做錯了什麼?Jenkins conditionalstep groovy腳本

編號:https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.conditionalSteps

代碼:

其被創建如圖

npm install 
mkdir buildArchive 

Conditional step 

而不是

Conditional step 
{ 
    npm install 
    mkdir buildArchive 
} 

我在做什麼錯

def configSeed(environment, slaveLabel) { 
    { it -> 
     parameters { 
     stringParam('BUILD_REQUIRED', 'true', ''); 
    } 
    scm { 
     git { 
      remote { 
       name('origin'); 
       url('xyz'); 
       refspec('$GERRIT_REFSPEC'); 
       credentials('xyz'); 
      } 
      branch('$GERRIT_BRANCH'); 
      strategy { 
       gerritTrigger(); 
      } 
     } 
    } 
    steps { 
     conditionalSteps { 
      condition { 
       stringsMatch('${BUILD_REQUIRED}', 'true', false) 
      } 
      runner('Fail') 
      steps { 
       environmentVariables { 
        envs(environment); 
       } 
       batchFile(''' 
        call npm install 
        ''');     
       batchFile(''' 
        call mkdir buildArchive 
        '''); 
      } 
     } 
    } 
    publishers { 
     wsCleanup { 
      includePattern('build/**') 
     } 
    } 
    wrappers { 
     preBuildCleanup(); 
     timeout { 
      noActivity(300); 
      abortBuild(); 
     } 
    } 
    label(slaveLabel); 
} 
}; 

所以詹金斯工作 這裏?

+0

什麼_「...列出的步驟是在條件塊之前...」是_是什麼意思? –

+0

@tim_yates更新了上述說明。我在上面的條件步驟之外看到命令,而不是在它之內。 – NxC

回答

2

當你生成你的腳步配置

job('foobar') { 
    steps { 
     conditionalSteps { 
      condition { 
       stringsMatch('${BUILD_REQUIRED}', 'true', false) 
      } 
      runner('Fail') 
      steps { 
       environmentVariables { 
        envs(FOO: 'bar', TEST: '123') 
       } 
       batchFile('call npm install')    
       batchFile('call mkdir buildArchive') 
      } 
     } 
    } 
} 

作業的結果似乎很動聽:

enter image description here

根據我的經驗,當你有作業DSL語法和任何問題,其結果,一個好的方法是區分作業的config.xml文件:

  • 根據需要手動配置作業,並保存config.xml
  • 在本地生成作業並保存config.xml
  • 區分兩個配置文件並查找確切的XML標記爲了
  • 然後嘗試和錯誤,看看是當你改變工作DSL腳本

要去當我開始使用作業DSL與常規的經驗 - 尤其是關閉) - 我有很多當我嘗試將作業配置塊提取到類似於您的情況的方法時出現類似問題。這是幫助我瞭解真正發生了什麼的。