當前位置:
首頁 > 知識 > 使用jenkins搭建自動化打包的apk 下載

使用jenkins搭建自動化打包的apk 下載

說明

  1. 更新到svn 以及發送到郵件有點慢,所有直接下載文件快
  2. 使用php做應用伺服器

頁面android.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="edge">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
ul, li {
list-style: none;
}

.box {
margin: 10px 10px;
text-align: left;
}

</style>
</head>
<body>
<div class="box">
<p>
說明:帶有Release是正式包的、帶有Debug是測試包;關鍵詞根據當前的關鍵字索引;
按照時間索引的話根據YYYY-MM-DD 的格式索引
</p>
<div>
app類型:
<select id="appKey">
<option value="">請選擇</option>

</select>
app類別:
<select id="appCategory">
<option value="">全部</option>
<option value="Debug">測試包</option>
<option value="Release">正式包</option>
</select>
關鍵詞:<input type="text" id="key"/>
<button type="button" id="select">搜索</button>
</div>
<br/>
<ul id="list">

</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
</script>
<script>
var path = "";
var arr = {
"0": "2017-09-20-14-20_ALL_v1.5.1_debug.apk",
"1": "2017-09-20-14-20_ALL_v1.5.1_debug.apk",
"2": "2017-09-20-14-20_ALL_v1.5.1_debug.apk",
"3": "2017-09-20-14-20_ALL_v1.5.1_debug.apk"
};
$.post("/softwarePackage/test2.php", {}, function (data) {
data = eval("(" + data + ")");
// console.log(data);
showDir(data);
});
var listArr = [];
$("#key").val(getNowFormatDate());
// showDir(arr);
function showDir(arr) {
var temp = [];
$.each(arr, function (k, v) {
// console.log(k)
// console.log(v)
temp.push("<li><a target="_blank" href="/softwarePackage/download.php?name=" + v + "">" + re(v) + "</a></li>");
// if("-".indexOf(k)>-1){
// $.each(v,function (k2,v2) {
// var path2 = k+"/";
// var arrTemp = v2.split(",");
// listArr.add("<li><a target="_blank" href="/softwarePackage/download.php?name="+path2+arrTemp[0]+"">"+k+">>>>"+arrTemp[0]+" "+arrTemp[1]+"</a></li>");
//// $("#list").append("<li><a target="_blank" href="/softwarePackage/download.php?name="+path2+arrTemp[0]+"">"+k+">>>>"+arrTemp[0]+" "+arrTemp[1]+"</a></li>")
// });
// }else {
// var arrTemp = v.split(",");
// $("#list").append("<li><a target="_blank" href="/softwarePackage/download.php?name="+path+arrTemp[0]+"">"+arrTemp[0]+" "+arrTemp[1]+"</a></li>")
// }
});
var len = temp.length;
for(var i=len-1;i>=0;i--){
listArr.push(temp[i]);
}
toList(listArr);
console.log(listArr);
}

$("#select").click(function () {
toList(listArr);
});
function toList(arr) {
$("#list").html("");
var key = $("#key").val();
var appKey = $("#appKey").val();
var appCategory = $("#appCategory").val();

for (var i = 0; i < arr.length; i++) {
var temp = arr[i];
var keyBool = key == "" ? true : temp.indexOf(key) > -1;
var appKeyBool = appKey == "" ? true : temp.indexOf(appKey) > -1;
var appCategoryKeyBool = appCategory == "" ? true : temp.indexOf(appCategory) > -1;
if (keyBool && appKeyBool && appCategoryKeyBool) {
$("#list").append(temp);
}

}
}
function re(str) {
str = str;
return str;
}
</script>
</html>
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

數據源

<?php
function get_dirs($dir_path) {
$res = array();
$res_lists = array();

foreach(glob("$dir_path/*") as $item) {
// $item = iconv("GB2312","UTF-8",$item);
if(is_dir($item)) {
$folder = end(explode("/", $item));
$res[$folder] =get_dirs($item);
continue;
}
$temp = "";
// if(file_exists($item)){
// $temp=",".date("Y-m-d H:i:s",filemtime($item));
// }

$res[] = basename($item.$temp);
}
return $res ;
}
// echo "<pre>";
echo json_encode(get_dirs("./android"));
// echo "</pre>";
?>
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

下載腳本

<?php

set_time_limit(0); //大文件在讀取內容未結束時會被超時處理,導致下載文件不全。

$fpath = "./android/".$_GET["name"];
$file_pathinfo = pathinfo($fpath);
$file_name = $file_pathinfo["basename"];
$file_extension = $file_pathinfo["extension"];
$handle = fopen($fpath,"rb");
if (FALSE === $handle)
exit("Failed to open the file");
$filesize = filesize($fpath);

header("Content-type:video/mpeg4");//更具不同的文件類型設置header輸出類型
header("Accept-Ranges:bytes");
header("Accept-Length:".$filesize);
header("Content-Disposition: attachment; filename=".$file_name);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename="" . $file_name . """);
header("Content-Length: ".$filesize);

$contents = "";
while (!feof($handle)) {
// $contents = fread($handle, 8192);
$contents = fread($handle, 1024*1024*10);
echo $contents;
@ob_flush(); //把數據從PHP的緩衝中釋放出來
flush(); //把被釋放出來的數據發送到瀏覽器
}
fclose($handle);
exit;
?>

使用jenkins搭建自動化打包的apk 下載

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

動態添加控制項及刪除
提取json字元串的內容(框架)

TAG:程序員小新人學習 |