2017-05-21 14 views
11

Ben bildirge Jenkins boru hattı içinde bir kilit içine birden çok aşamadan çalıştırmak istiyorum:Deklarasyonlu Jenkins boru hattının çeşitli aşamaları nasıl kilitlenir?

pipeline { 
    agent any 
    stages { 
     lock(resource: 'myResource') { 
      stage('Stage 1') { 
       steps { 
        echo "my first step" 
       } 
      } 

      stage('Stage 2') { 
       steps { 
        echo "my second step" 
       } 
      } 

     } 
    } 
} 

aşağıdaki hatayı alıyorum: Sorun Burada ne var

Started by user anonymous 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 
WorkflowScript: 10: Expected a stage @ line 10, column 9. 
      lock(resource: 'myResource') { 
     ^

WorkflowScript: 10: Stage does not have a name @ line 10, column 9. 
      lock(resource: 'myResource') { 
     ^

WorkflowScript: 10: Nothing to execute within stage "null" @ line 10, column 9. 
      lock(resource: 'myResource') { 
     ^

3 errors 

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) 
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085) 
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603) 
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) 
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) 
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) 
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) 
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) 
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700) 
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:116) 
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430) 
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393) 
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:257) 
    at hudson.model.ResourceController.execute(ResourceController.java:97) 
    at hudson.model.Executor.run(Executor.java:405) 
Finished: FAILURE 

? documentation açıkça belirtmektedir:

lock can be also used to wrap multiple stages into a single concurrency unit

cevap

8

sorun bildirim boru hatları technically available in beta in September, 2016 gerçeğine rağmen, blog postasına o kadar demiyor (deklaratif değil metne boru hatlarını belgeliyor (Ekim-) referans, yani , bu yüzden senin acılarını hissediyorum). Kilitlenebilir kaynaklar henüz aradığınız özelliği etkinleştirecek şekilde bildirimsel bir boru hattı adımı olarak yapılmadı.

pipeline { 
    agent { label 'docker' } 
    stages { 
    stage('one') { 
     steps { 
     lock('something') { 
      echo 'stage one' 
     } 
     } 
    } 
    } 
} 

Ama yapamaz:

bunu yapabilirsiniz

pipeline { 
    agent { label 'docker' } 
    stages { 
    lock('something') { 
     stage('one') { 
     steps { 
      echo 'stage one' 
     } 
     } 
     stage('two') { 
     steps { 
      echo 'stage two' 
     } 
     } 
    } 
    } 
} 

Ve yapamaz:

pipeline { 
    agent { label 'docker' } 
    stages { 
    stage('one') { 
     lock('something') { 
     steps { 
      echo 'stage one' 
     } 
     } 
    } 
    } 
} 

Sen bir metne boru hattı kullanabilirsiniz Bu kullanım durumu.

+0

konu hala açık: https://issues.jenkins-ci.org/browse/JENKINS-43336 –

+0

Bu kilit, kilitlenebilir kaynak eklentisi gerektirir: https://plugins.jenkins.io/lockable-resources –

11
kilit seçeneğini kullanarak bir boru hattı tüm aşamalarını kilitleyebilir unutulmamalıdır

:

pipeline { 
    agent any 
    options { 
     lock resource: 'shared_resource_lock' 
    } 
    stages { 
     stage('will_already_be_locked') { 
      steps { 
       echo "I am locked before I enter the stage!" 
      } 
     } 
     stage('will_also_be_locked') { 
      steps { 
       echo "I am still locked!" 
      } 
     } 
    } 
} 
+0

bu bizim için çalıştı. –

İlgili konular