一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - jenkins中如何集成commander應用的完整步驟

jenkins中如何集成commander應用的完整步驟

2021-04-28 11:57貝克田莊 Java教程

jenkins是一個用java編寫的開源的持續集成工具,在與oracle發生爭執后,項目從hudson項目獨立出來,下面這篇文章主要給大家介紹了關于jenkins中如何集成commander應用的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參

前言

jenkins 是一款流行的開源持續集成(continuous integration)工具,廣泛用于項目開發,具有自動化構建、測試和部署等功能。

最近參加公司的集成測試平臺的開發,在開發中遇到了不少問題,兩個星期的迭代也即將完成,在這也用這篇博客記錄下開發中的問題,供讀者參考

公司的應用較多,所以需要了解這幾種應用在jenkins中如何做構建,我自己參與的有兩種commander的應用,一種是大數據類的,一個是我們服務端架構組的scala應用

1、大數據應用bigdata

配置如下:

jenkins中如何集成commander應用的完整步驟

jenkins中如何集成commander應用的完整步驟

配置文件對應的xml文件:通過crul獲取xml配置文件:http://host/job/tar_py_dwx_dev/config.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<project>
<actions/>
<description/>
<keepdependencies>false</keepdependencies>
<properties>
<com.dabsquared.gitlabjenkins.connection.gitlabconnectionproperty plugin="[email protected]">
<gitlabconnection/>
</com.dabsquared.gitlabjenkins.connection.gitlabconnectionproperty>
<hudson.plugins.promoted__builds.jobpropertyimpl plugin="[email protected]">
<activeprocessnames>
<string>deploy dev</string>
</activeprocessnames>
</hudson.plugins.promoted__builds.jobpropertyimpl>
</properties>
<scm class="hudson.plugins.git.gitscm" plugin="[email protected]">
<configversion>2</configversion>
<userremoteconfigs>
<hudson.plugins.git.userremoteconfig>
<url>ssh://[email protected]: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中獲取的信息有點和圖中的配置文件有點對應不上

對于promotion的腳本在xml配置文件中是無法獲取的,這時候就有一個問題,這種api是無法獲取到promotion的的腳本,同時這也給我們的工作帶來了極大的挑戰,那也意味著單純的通過這種方法是無法實現commander應用的部署,和通過平臺的方式去直接操作jenkins的配置

但經過查詢相關的api并不能找到相關的內容,經過不懈的努力,終于找到了和promote build 插件相關的api

查詢:http://host/job/jobname/promotion/process/promotionname/config.xml

這個接口能獲取到它的xml文件,但是并不能對該配置文件進行增加和修改

對此我自己封裝了一些方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * @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("初創promotion時失敗" + e);
 }
 jenkinspromotionclient.createjob(jobname, promotionname, document.asxml());
 }
 
 public static string getpromotionname(document jobconfigdocument, string path) {
 return jobconfigdocument.selectsinglenode(path).gettext();
 }
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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腳本的構建
 * @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");
 }
 }
}

其中的方法封裝了對promote build插件中關于配置的增刪改查,以及promotion腳本的構建

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:https://www.cnblogs.com/clovejava/archive/2018/05/13/9033704.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本国产在线视频 | 3d美女触手怪爆羞羞漫画 | 午夜视频在线网站 | 亚洲AV国产国产久青草 | 色综合91久久精品中文字幕 | 精品日韩欧美一区二区三区在线播放 | 数学老师扒开腿让我爽快 | 亚洲精品有码在线观看 | 日本色频 | 九九免费高清在线观看视频 | 久久成人永久免费播放 | 国产激情视频在线 | 波多野给衣一区二区三区 | 精品国产在天天线在线麻豆 | 91精品手机国产在线观 | 亚洲人成综合在线播放 | 91专区| 日本免费三片在线播放 | 国产普通话对白露脸流出 | 性奴公司 警花 | 秋霞717理论片在线观看 | 动漫女性扒开尿口羞羞漫画 | 亚久久伊人精品青青草原2020 | 黑人开嫩苞 | 网址在线观看你懂我意思吧免费的 | 激情三级做爰在线观看激情 | 日产精品视频 | 五月天婷婷网亚洲综合在线 | 福利国产片 | 大团圆免费阅读全文 | 毛片在线播放a | 护士被多人调教到失禁h | 国产日产精品久久久久快鸭 | 午夜神器老司机高清无码 | 大香焦在线观看 | 亚洲高清毛片一区二区 | 国产成人精品午夜视频' | 第一次破学生处破 | 国产激情一区二区三区成人91 | 小寡妇水真多好紧 | 我和么公的秘密小说免费 |