2016-06-14 6 views
0

을 사용하는 모든 작업에 대해 작업 시간 초과를 설정하는 방법은 How can I set the job timeout using the Jenkins DSL입니다. 그러면 한 작업의 시간 초과가 설정됩니다. 모든 작업에 대해 설정을 약간 다르게하고 싶습니다 : 150 %, 10 개 작업의 평균, 최대 30 분.Jenkins DSL

relevant job-dsl-plugin documentation에 따르면 나는이 구문을 사용한다 :

job('example-3') { 
    wrappers { 
     timeout { 
      elastic(150, 10, 30) 
      failBuild() 
      writeDescription('Build failed due to timeout after {0} minutes') 
     } 
    } 
} 

내가 http://job-dsl.herokuapp.com/에서 테스트하고이 관련 XML의 일부입니다

<buildWrappers> 
    <hudson.plugins.build__timeout.BuildTimeoutWrapper> 
     <strategy class='hudson.plugins.build_timeout.impl.ElasticTimeOutStrategy'> 
      <timeoutPercentage>150</timeoutPercentage> 
      <numberOfBuilds>10</numberOfBuilds> 
      <timeoutMinutesElasticDefault>30</timeoutMinutesElasticDefault> 
     </strategy> 
     <operationList> 
      <hudson.plugins.build__timeout.operations.FailOperation></hudson.plugins.build__timeout.operations.FailOperation> 
      <hudson.plugins.build__timeout.operations.WriteDescriptionOperation> 
       <description>Build failed due to timeout after {0} minutes</description> 
      </hudson.plugins.build__timeout.operations.WriteDescriptionOperation> 
     </operationList> 
    </hudson.plugins.build__timeout.BuildTimeoutWrapper> 
</buildWrappers> 

나는 내가 전에 수동으로 편집 작업 확인을, XML이 정확합니다. 그래서 젠킨스의 DSL 구문이 정확하다는 것을 알고 있습니다.


이제이를 모든 작업에 적용하고 싶습니다. 먼저 모든 작업 이름을 나열하려고 시도했습니다.

import jenkins.model.* 

jenkins.model.Jenkins.instance.items.findAll().each { 
    println("Job: " + it.name) 
} 

이 경우에도 모든 작업 이름이 콘솔에 인쇄됩니다.


이제는 모두 함께 연결하고 싶습니다. 이는 전체 코드는 내가 사용된다

ERROR: Type of item "jobname" does not match existing type, item type can not be changed 

내가 잘못 여기서 뭐하는 거지 :이 코드를 밀어 젠킨스는 DSL 종자 작업을 실행하면

import jenkins.model.* 

jenkins.model.Jenkins.instance.items.findAll().each { 
    job(it.name) { 
    wrappers { 
     timeout { 
     elastic(150, 10, 30) 
     failBuild() 
     writeDescription('Build failed due to timeout after {0} minutes') 
     } 
    } 
    } 
} 

, 나는이 오류가?

답변

1

Job-DSL 플러그인은 이전에 해당 플러그인으로 작성된 작업을 유지하는 데에만 사용할 수 있습니다. 다른 방법으로 생성 된 작업의 구성을 수정하려고합니다. 작동하지 않습니다.

기존 작업의 대량 수정 (같은, 귀하의 경우, 제한 시간을 추가)의 경우 가장 간단한 방법은 디스크에 config.xml 파일을 변경하여

  • 하거나, 직접 작업의 XML 사양을 변경하는 것입니다, 또는 REST 또는 CLI API

xmlstarlet를 사용

  • 쉘 수준에 직접적으로 같은 작업을 수행하기위한 강력한 도구입니다.

    또는 "Script Console"에서 Groovy 스크립트를 통해 변경을 수행 할 수 있습니다. 그러나이를 위해서는 Jenkins의 내부 작동 및 데이터 구조에 대한 이해가 필요합니다.

  • +0

    감사합니다. Job-DSL 플러그인이 그 플러그인으로 생성 된 작업 만 유지할 수 있다고 언급 한 문서를 찾지 못했습니다. 솔직히, 그것은 나를 위해 사용성을 심각하게 제한합니다. xmlstarlet을 제안 해 주셔서 감사합니다. 과거에 사용해 왔습니다. 아니면 grep & sed 마법을 적용 해 보겠습니다. –