最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jenkins中如何集成commander應(yīng)用的完整步驟

 更新時(shí)間:2018年05月14日 09:40:59   作者:貝克田莊  
jenkins是一個(gè)用java編寫(xiě)的開(kāi)源的持續(xù)集成工具,在與oracle發(fā)生爭(zhēng)執(zhí)后,項(xiàng)目從hudson項(xiàng)目獨(dú)立出來(lái),下面這篇文章主要給大家介紹了關(guān)于jenkins中如何集成commander應(yīng)用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下

前言

Jenkins 是一款流行的開(kāi)源持續(xù)集成(Continuous Integration)工具,廣泛用于項(xiàng)目開(kāi)發(fā),具有自動(dòng)化構(gòu)建、測(cè)試和部署等功能。

最近參加公司的集成測(cè)試平臺(tái)的開(kāi)發(fā),在開(kāi)發(fā)中遇到了不少問(wèn)題,兩個(gè)星期的迭代也即將完成,在這也用這篇博客記錄下開(kāi)發(fā)中的問(wèn)題,供讀者參考

公司的應(yīng)用較多,所以需要了解這幾種應(yīng)用在jenkins中如何做構(gòu)建,我自己參與的有兩種commander的應(yīng)用,一種是大數(shù)據(jù)類的,一個(gè)是我們服務(wù)端架構(gòu)組的scala應(yīng)用

1、大數(shù)據(jù)應(yīng)用BigData

配置如下:

 

配置文件對(duì)應(yīng)的xml文件:通過(guò)crul獲取xml配置文件:http://host/job/tar_py_dwx_dev/config.xml

<project>
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.5">
<gitLabConnection/>
</com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
<hudson.plugins.promoted__builds.JobPropertyImpl plugin="promoted-builds@3.1">
<activeProcessNames>
<string>Deploy DEV</string>
</activeProcessNames>
</hudson.plugins.promoted__builds.JobPropertyImpl>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.8.0">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>ssh://git@172.0.10.182:10022/bigdata/dwx.git</url>
<credentialsId>84f4be19-ea8d-4271-8cfb-42af8f507285</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/develop</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
<assignedNode>!macmini</assignedNode>
<canRoam>false</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<hudson.triggers.SCMTrigger>
<spec>H/5 * * * *</spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>
project=dwx1 cd ${WORKSPACE} tar zcvf ${project}.tar.gz * aws s3 cp ${project}.tar.gz s3://lattebank-jenkins-build-dev/${JOB_BASE_NAME}/${BUILD_NUMBER}/ --region cn-north-1 rm -rf ${project}.tar.gz
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

從xml中獲取的信息有點(diǎn)和圖中的配置文件有點(diǎn)對(duì)應(yīng)不上

對(duì)于promotion的腳本在xml配置文件中是無(wú)法獲取的,這時(shí)候就有一個(gè)問(wèn)題,這種api是無(wú)法獲取到promotion的的腳本,同時(shí)這也給我們的工作帶來(lái)了極大的挑戰(zhàn),那也意味著單純的通過(guò)這種方法是無(wú)法實(shí)現(xiàn)commander應(yīng)用的部署,和通過(guò)平臺(tái)的方式去直接操作jenkins的配置

但經(jīng)過(guò)查詢相關(guān)的api并不能找到相關(guān)的內(nèi)容,經(jīng)過(guò)不懈的努力,終于找到了和promote build 插件相關(guān)的api

查詢:http://host/job/jobName/promotion/process/promotionName/config.xml

這個(gè)接口能獲取到它的xml文件,但是并不能對(duì)該配置文件進(jìn)行增加和修改

對(duì)此我自己封裝了一些方法:

/**
 * @author chenlang
 * date 2018/5/7
 */
@Slf4j
public class JenkinsPromotionUtils {
 
 
 private static final String SUB_PATH_PROMOTION_COOMMAND = "/hudson.plugins.promoted__builds.PromotionProcess";
 private static final String SUB_PATH_BUILD = "/buildSteps";
 private static final String SUB_PATH_BUILDER_SHELL_COMMAND = "/hudson.tasks.Shell/command";
 private static final String PATH_PROMOTION_COMMAND = SUB_PATH_PROMOTION_COOMMAND + SUB_PATH_BUILD + SUB_PATH_BUILDER_SHELL_COMMAND;
 private static String CREATE_PROMOTION_JSON = "{'properties':{'stapler-class-bag':'true','hudson-plugins-promoted_builds-JobPropertyImpl':{'promotions':{'activeItems':{'name':'%s','isVisible':'','icon':'star-gold','hasAssignedLabel':false,'assignedLabelString':'','conditions':{'stapler-class-bag':'true'}}}}}}";
 private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
 
 
 public static void updatePromotionShell(Document jobConfigDocument, String jobName, JenkinsPromotionClient jenkinsPromotionClient, String promotionShell, String path) throws IOException, DocumentException {
 if (StringUtils.isBlank(promotionShell)) {
  return;
 }
 String promotionName = getPromotionName(jobConfigDocument, path);
 Document document = jenkinsPromotionClient.getJobPromotionXml(jobName, promotionName);
 document.selectSingleNode(PATH_PROMOTION_COMMAND).setText(promotionShell);
 jenkinsPromotionClient.updateJob(jobName, promotionName, document.asXML());
 }
 
 public static void createPromotionShell(Document jobConfigDocument, String tmpJobName, String jobName, String promotionShell, String path, JenkinsPromotionClient jenkinsPromotionClient) throws IOException, DocumentException {
 if (StringUtils.isBlank(promotionShell)) {
  return;
 }
 String promotionName = getPromotionName(jobConfigDocument, path);
 Document document = jenkinsPromotionClient.getJobPromotionXml(tmpJobName, promotionName);
 document.selectSingleNode(PATH_PROMOTION_COMMAND).setText(promotionShell);
 Map<String, String> map = Maps.newHashMap();
 map.put("Content-Type", CONTENT_TYPE);
 map.put("json", String.format(CREATE_PROMOTION_JSON, promotionName));
 try {
  jenkinsPromotionClient.createJob(jobName, map);
 } catch (Exception e) {
  log.error("初創(chuàng)promotion時(shí)失敗" + e);
 }
 jenkinsPromotionClient.createJob(jobName, promotionName, document.asXML());
 }
 
 public static String getPromotionName(Document jobConfigDocument, String path) {
 return jobConfigDocument.selectSingleNode(path).getText();
 }
}
package cn.caijiajia.phoenix.service.jenkins;
import com.offbytwo.jenkins.client.JenkinsHttpClient;
import com.offbytwo.jenkins.client.util.EncodingUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;
 
/**
 * @author chenlang
 * date 2018/5/4
 */
@Component
public class JenkinsPromotionClient {
 
 @Autowired
 private JenkinsHttpClient jenkinsHttpClient;
 
 public JenkinsPromotionClient() {
 }
 
 /**
 * 獲取job的promotion配置文件
 *
 * @param jobName job名稱
 * @param promotionName promotion名稱
 * @return
 * @throws IOException
 */
 public Document getJobPromotionXml(String jobName, String promotionName) throws IOException, DocumentException {
 return DocumentHelper.parseText(this.getJobXml(jobName, promotionName));
 }
 
 
 /**
 * 更新job
 *
 * @param jobName
 * @param promotionName
 * @param jobXml
 * @throws IOException
 */
 public void updateJob(String jobName, String promotionName, String jobXml) throws IOException {
 this.jenkinsHttpClient.post_xml(this.toJobBaseUrl(jobName, promotionName) + "/config.xml", jobXml, true);
 }
 
 /**
 * 添加job腳本
 *
 * @param jobName
 * @param jobXml
 * @throws IOException
 */
 public void createJob(String jobName, String promotionName, String jobXml) throws IOException {
 this.jenkinsHttpClient.post_xml(this.toJobBaseUrl(jobName, promotionName) + "/config.xml", jobXml, true);
 }
 
 /**
 * 添加promotion的job
 *
 * @param jobName
 * @param map
 * @throws IOException
 */
 public void createJob(String jobName, Map map) throws IOException {
 this.jenkinsHttpClient.post_form("/job/" + EncodingUtils.encode(jobName) + "/configSubmit?", map, false);
 }
 
 private String getJobXml(String jobName, String promotionName) throws IOException {
 return this.jenkinsHttpClient.get(this.toJobBaseUrl(jobName, promotionName) + "/config.xml");
 }
 
 private String toJobBaseUrl(String jobName, String promotionName) {
 return "/job/" + EncodingUtils.encode(jobName) + "/promotion/process/" + promotionName;
 }
 
 /**
 * promotion腳本的構(gòu)建
 * @param jobName
 * @param promotionName
 * @param version
 * @param isFirstBuild
 * @throws IOException
 */
 public void build(String jobName,String promotionName,Integer version,boolean isFirstBuild) throws IOException{
 if (isFirstBuild) {
  this.jenkinsHttpClient.post("/job/"+ EncodingUtils.encode(jobName) + "/"+version+"/promotion/forcePromotion?name="+promotionName+"&json=%7B%7D&Submit=Force promotion");
 } else {
  this.jenkinsHttpClient.post("/job/"+ EncodingUtils.encode(jobName) + "/"+version+"/promotion/"+promotionName+"/build?json=%7B%7D&Submit=Re-execute promotion");
 }
 }
}

其中的方法封裝了對(duì)promote build插件中關(guān)于配置的增刪改查,以及promotion腳本的構(gòu)建

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
 

相關(guān)文章

  • Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理

    Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理

    這篇文章主要介紹了Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Spring之詳解bean的實(shí)例化

    Spring之詳解bean的實(shí)例化

    這篇文章主要介紹了Spring之詳解bean的實(shí)例化,文章內(nèi)容詳細(xì),簡(jiǎn)單易懂,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2023-01-01
  • Java調(diào)用參數(shù)類型是application/x-www-form-urlencoded的API問(wèn)題

    Java調(diào)用參數(shù)類型是application/x-www-form-urlencoded的API問(wèn)題

    在使用Postman進(jìn)行接口測(cè)試時(shí),對(duì)于POST請(qǐng)求,需將請(qǐng)求頭設(shè)置為application/x-www-form-urlencoded,并將參數(shù)轉(zhuǎn)為String類型,通常在GET請(qǐng)求中,參數(shù)直接拼接在URL后,本文通過(guò)具體實(shí)例,詳細(xì)講解了參數(shù)處理的方法,適合API開(kāi)發(fā)者參考
    2024-09-09
  • SpringBoot整合mybatis-plus快速入門(mén)超詳細(xì)教程

    SpringBoot整合mybatis-plus快速入門(mén)超詳細(xì)教程

    mybatis-plus 是一個(gè) Mybatis 的增強(qiáng)工具,在 Mybatis 的基礎(chǔ)上只做增強(qiáng)不做改變,為簡(jiǎn)化開(kāi)發(fā)、提高效率而生,本文給大家分享SpringBoot整合mybatis-plus快速入門(mén)超詳細(xì)教程,一起看看吧
    2021-09-09
  • 聊聊springboot2.2.3升級(jí)到2.4.0單元測(cè)試的區(qū)別

    聊聊springboot2.2.3升級(jí)到2.4.0單元測(cè)試的區(qū)別

    這篇文章主要介紹了springboot 2.2.3 升級(jí)到 2.4.0單元測(cè)試的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java 數(shù)據(jù)結(jié)構(gòu)之刪除鏈表中重復(fù)的結(jié)點(diǎn)

    Java 數(shù)據(jù)結(jié)構(gòu)之刪除鏈表中重復(fù)的結(jié)點(diǎn)

    在一個(gè)排序的鏈表中,會(huì)存在重復(fù)的結(jié)點(diǎn),如何實(shí)現(xiàn)刪除該鏈表中重復(fù)的結(jié)點(diǎn),重復(fù)的結(jié)點(diǎn)不保留,并返回鏈表頭指針呢?接下來(lái)小編將帶你詳細(xì)介紹
    2021-12-12
  • java實(shí)現(xiàn)ftp上傳 如何創(chuàng)建文件夾

    java實(shí)現(xiàn)ftp上傳 如何創(chuàng)建文件夾

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)ftp上傳的相關(guān)資料,教大家如何創(chuàng)建文件夾?具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • springboot下添加日志模塊和設(shè)置日志文件輸出的方法

    springboot下添加日志模塊和設(shè)置日志文件輸出的方法

    日志的使用將通過(guò)SLF4J來(lái)使用,SLF4J是一個(gè)為Java應(yīng)用提供簡(jiǎn)單日志記錄的接口,在Spring框架中,SLF4J常常用于處理框架本身以及應(yīng)用程序的日志記錄,本文給大家介紹springboot下添加日志模塊和設(shè)置日志文件輸出的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2023-12-12
  • Java線性表的順序表示及實(shí)現(xiàn)

    Java線性表的順序表示及實(shí)現(xiàn)

    這篇文章主要介紹了Java線性表的順序表示及實(shí)現(xiàn),順序表是在計(jì)算機(jī)內(nèi)存中以數(shù)組的形式保存的線性表,線性表的順序存儲(chǔ)是指用一組地址連續(xù)的存儲(chǔ)單元依次存儲(chǔ)線性表中的各個(gè)元素、使得線性表中在邏輯結(jié)構(gòu)上相鄰的數(shù)據(jù)元素存儲(chǔ)在相鄰的物理存儲(chǔ)單元中
    2022-07-07
  • Spring Boot引入swagger-ui 后swagger-ui.html無(wú)法訪問(wèn)404的問(wèn)題

    Spring Boot引入swagger-ui 后swagger-ui.html無(wú)法訪問(wèn)404的問(wèn)題

    這篇文章主要介紹了Spring Boot引入swagger-ui 后swagger-ui.html無(wú)法訪問(wèn)404的問(wèn)題及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09

最新評(píng)論

周口市| 如皋市| 宜城市| 仁怀市| 济宁市| 绵竹市| 沽源县| 托克托县| 兰溪市| 门源| 博兴县| 镇江市| 来凤县| 五常市| 宁海县| 洮南市| 新竹市| 浑源县| 阜宁县| 湾仔区| 土默特右旗| 绵竹市| 抚远县| 罗城| 遂溪县| 泸西县| 太湖县| 兴山县| 宿迁市| 保康县| 山阴县| 阿克陶县| 安顺市| 光泽县| 通辽市| 和田市| 安岳县| 涟水县| 宜章县| 乌拉特中旗| 蒙山县|