av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

實踐:JenkinsCoreApi&JobDSL創(chuàng)建項目

 在大規(guī)模的Jenkins實踐中創(chuàng)建項目也是一個問題,如何通過模板自動化的創(chuàng)建Jenkins項目呢? 可以通過安裝Job Dsl插件后,通過 Dsl直接創(chuàng)建項目。也可以通過工具將dsl轉(zhuǎn)換為xml,然后再通過Jenkins API創(chuàng)建項目。相對比較第一種方式更加直接一些,由于時間問題今天暫時分享第二種創(chuàng)建項目的方式。

創(chuàng)新互聯(lián)于2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計、成都做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元湛江做網(wǎng)站,已為上家服務(wù),為湛江各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108

1.根據(jù)Job DSL API生成模板

我們需要先安裝好Job Dsl 插件,然后執(zhí)行DSL創(chuàng)建項目。地址:https://jenkinsci.github.io/job-dsl-plugin/

例如: 使用官網(wǎng)的example。這里定義了一個流水線項目,配置了項目的信息包括(項目描述、項目參數(shù)、Jenkinsfile地址)

 
 
 
 
  1. pipelineJob("test-schdule-service") { 
  2.   description("this is my first job") 
  3.   keepDependencies(false) 
  4.   parameters { 
  5.     choiceParam("test", [1, 2, 3], "") 
  6.   } 
  7.   definition { 
  8.     cpsScm { 
  9.       scm { 
  10.         git { 
  11.           remote { 
  12.             github("https://gitlab.com/xxx/xxx.git", "https") 
  13.             credentials("24982560-17fc-4589-819b-bc5bea89da77") 
  14.           } 
  15.           branch("*/master") 
  16.         } 
  17.       } 
  18.       scriptPath("Jenkinsfile") 
  19.     } 
  20.   } 
  21.   disabled(false) 

2.通過Playground轉(zhuǎn)換DSL -> XML

url: http://job-dsl.herokuapp.com/

3.通過Jenkins Core Api創(chuàng)建項目

 
 
 
 
  1. import javax.xml.transform.stream.StreamSource 
  2. import jenkins.model.Jenkins 
  3.  
  4. //創(chuàng)建項目 
  5. void createOrUpdateJob(String name, String xml) { 
  6.     def j = Jenkins.instance 
  7.     String fullName = name 
  8.     if(name.contains('/')) { 
  9.         j = j.getItemByFullName(name.tokenize('/')[0..-2]) 
  10.         name = name.tokenize('/')[-1] 
  11.     } 
  12.     Jenkins.checkGoodName(name) 
  13.     if(j.getItem(name) == null) { 
  14.         println "Created job \"${fullName}\"." 
  15.         j.createProjectFromXML(name, new ByteArrayInputStream(xml.getBytes())) 
  16.         j.save() 
  17.     } 
  18.     else if(j.getItem(name).configFile.asString().trim() != xml.trim()) { 
  19.         j.getItem(name).updateByXml(new StreamSource(new ByteArrayInputStream(xml.getBytes()))) 
  20.         j.getItem(name).save() 
  21.         println "Job \"${fullName}\" already exists.  Updated using XML." 
  22.     } 
  23.     else { 
  24.         println "Nothing changed.  Job \"${fullName}\" already exists." 
  25.     } 
  26.  
  27. try { 
  28.     //just by trying to access properties should throw an exception 
  29.     itemName == null 
  30.     xmlData == null 
  31.     isPropertiesSet = true 
  32. } catch(MissingPropertyException e) { 
  33.     println 'ERROR Can\'t create job.' 
  34.     println 'ERROR Missing properties: itemName, xmlData' 
  35.     return 
  36.  
  37. String xmlData = """ 
  38.  
  39.      
  40.     this is my first job 
  41.     false 
  42.      
  43.          
  44.              
  45.                  
  46.                      
  47.                          
  48.                             1 
  49.                             2 
  50.                             3 
  51.                          
  52.                      
  53.                     test 
  54.                      
  55.                  
  56.              
  57.          
  58.          
  59.             https://github.com/https://gitlab.com/xxx/xxx.git/ 
  60.          
  61.      
  62.      
  63.      
  64.         Jenkinsfile 
  65.         false 
  66.          
  67.              
  68.                  
  69.                     https://github.com/https://gitlab.com/xxx/xxx.git.git 
  70.                     24982560-17fc-4589-819b-bc5bea89da77 
  71.                  
  72.              
  73.              
  74.                  
  75.                     */master 
  76.                  
  77.              
  78.             2 
  79.             false 
  80.             Default 
  81.              
  82.                 https://github.com/https://gitlab.com/xxx/xxx.git/ 
  83.              
  84.          
  85.      
  86.     false 
  87.  
  88. """ 
  89. String itemName = "my-first-pipeline" 
  90.  
  91. createOrUpdateJob(itemName, xmlData) 

4.通過Jenkins Script Console運行

創(chuàng)建完成


網(wǎng)頁題目:實踐:JenkinsCoreApi&JobDSL創(chuàng)建項目
網(wǎng)頁鏈接:http://uogjgqi.cn/article/cdjisij.html

掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流