2017-07-04 112 views
0

我正在用Dockerfile構建Jenkins,並且在Docker構建期間,我想讓Jenkins預先配置一組作業。我發現這與喬布斯DSL的工作很好,工作是播種,但我還沒有預先配置「管道」DSL。鑑於詹金斯的方向和使用Jenkisfile,管道等,我認爲必須有一些辦法可以讓詹金斯自動與一組作業是用流水線的方式使用管道作業初始化Jenkins

例管道建成運行:

pipeline { 
     agent { 
      label 'cft' 
     } 
parameters { 
     string(name: 'StackName', defaultValue: 'cft-stack', description: 'The name to give the CFT stack.') 
     string(name: 'KeyName', defaultValue: 'ACCOUNT', description: 'The account key to use for encryption.') 
     string(name: 'VpcId', defaultValue: 'vpc-1234', description: 'The VPC to assign to the cluster resources.') 
     string(name: 'SubnetID', defaultValue: 'subnet-1234, subnet-6789', description: 'The subnet(s) to assign to the cluster resources.') 
    stages { 

     stage('Build') { 

      steps { 

       s3Download(file:'cft.yaml' 
        , bucket:'cft-resources' 
        , path:'cft.yaml' 
        , force:true) 

       cfnUpdate(stack:"${params.StackName}" 
        , file:"cft.yaml" 
        , params:[ 
        "SnapshotId=${params.SnapshotId}", 
        "KeyName=${params.KeyName}", 
        "VpcId=${params.VpcId}" 
        ] 
        , timeoutInMinutes: 20 
       ) 
      } 
     } 
    } 
    post { 
     failure { 
      echo 'FAILURE' 
      cfnDelete(stack:"${params.StackName}") 
     } 
    }  
} 

Dockerfile:

COPY ./groovy/*.groovy /usr/share/jenkins/ref/init.groovy.d/

回答

0

管道的Groovy文件從可以執行的配置詹金斯的Groovy代碼不同。您不能按照您嘗試的方式添加管道。

您的選項包括

  • 副本任務定義XML文件(指向您的回購,作爲管道應在Jenkinsfile在回購)
  • 使用Groovy創建一個作業並對其進行配置(不是真正可行的IMHO)
  • 使用JobDSL(再次,以XML爲出發點)指定您的Jenkins作業。自動添加此示例可以在tknerr/jenkins-pipes-infra中找到。
相關問題