jenkins构建脚本:
[root@localhost tomcat]# cat move.sh
#!/bin/bash
release_dir=/data/android_git/app/build/outputs/apk/tuji/release
debug_dir=/data/android_git/app/build/outputs/apk/tuji/debug
releasetest_dir=/data/android_git/app/build/outputs/apk/tuji/releaseTest
function release ()
{
cd /data/android_git && gradle clean
cd /data/android_git && gradle assembleTujiRelease
if [ -d $release_dir ];then
cd $release_dir
apk=`ls -lt|grep .apk|awk -F " " '{print $NF}'`
new_time=`date +%Y%m%d%H%M`
version=`echo $apk | awk -F ".apk" '{print $1}'`
new_apk=$version-$new_time.apk
mv $apk $new_apk
cp -rf $release_dir/$new_apk /data/download/release
python3 /home/tomcat/jenkins_android_test.py $new_apk release
else
python3 /home/tomcat/jenkins_android_test.py path_release_error
fi
}
function debug ()
{
cd /data/android_git && gradle clean
cd /data/android_git && gradle assembleTujiDebug
if [ -d $debug_dir ];then
cd $debug_dir
apk=`ls -lt|grep .apk|awk -F " " '{print $NF}'`
new_time=`date +%Y%m%d%H%M`
version=`echo $apk | awk -F ".apk" '{print $1}'`
new_apk=$version-$new_time.apk
mv $apk $new_apk
cp -rf $debug_dir/$new_apk /data/download/debug
python3 /home/tomcat/jenkins_android_test.py $new_apk debug
else
python3 /home/tomcat/jenkins_android_test.py path_debug_error
fi
}
function releasetest ()
{
cd /data/android_git && gradle clean
cd /data/android_git && gradle assembleTujiReleaseTest
if [ -d $releasetest_dir ];then
cd $releasetest_dir
apk=`ls -lt|grep .apk|awk -F " " '{print $NF}'`
new_time=`date +%Y%m%d%H%M`
version=`echo $apk | awk -F ".apk" '{print $1}'`
new_apk=$version-$new_time.apk
mv $apk $new_apk
cp -rf $releasetest_dir/$new_apk /data/download/releasetest
python3 /home/tomcat/jenkins_android_test.py $new_apk releasetest
else
python3 /home/tomcat/jenkins_android_test.py path_releasetest_error
fi
}
case $1 in
release)
echo release runing
release;
;;
debug)
echo debug ruing
debug;
;;
releasetest)
echo releasetest runing
releasetest;
;;
*)
release;
debug;
releasetest;
;;
esac
构建成功WEBHOOK提醒
#!/usr/local/python-3.6.4/bin/python3
from urllib import request
import json
from sys import argv
import time
#获得当前时间时间戳
now = int(time.time())
#转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"
timeStruct = time.localtime(now)
strTime = time.strftime("%Y-%m-%d %H:%M:%S", timeStruct)
access_token = ""
#def send_msg(mobile, item_name):
def send_msg(time_str,apk_name,download_dir=False):
if download_dir:
content=apk_name + ' ' + time_str + ' ' + 'http://ip?/download/' + download_dir + "/"
else:
content=apk_name + ' ' + time_str
url = "https://oapi.dingtalk.com/robot/send?access_token=" + access_token
data = {
"msgtype": "text",
"text": {
"content": content
},
"at": {
#"atMobiles": \[
# mobile
#\],
"isAtAll": "false"
}
}
json\_data= json.dumps(data).encode(encoding='utf-8')
print(json\_data)
header\_encoding = {"Content-Type": "application/json"}
req = request.Request(url=url, data=json\_data, headers=header\_encoding)
res = request.urlopen(req)
res = res.read()
print(res.decode(encoding='utf-8'))
if __name__ == "__main__":
time_str = strTime
if len(argv) == 3:
apk_name=argv[1]
download_dir=argv[2]
send_msg(time_str,apk_name,download_dir)
else:
apk_name = argv[1]
send_msg(time_str,apk_name)
nginx作为下载服务器配置:
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
user nobody;
worker_processes 1;
error_log logs/error.log warn;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log\_format main '$remote\_addr - $remote\_user \[$time\_local\] "$request" '
'$status $body\_bytes\_sent "$http\_referer" '
'"$http\_user\_agent" "$http\_x\_forwarded\_for"';
access\_log logs/access.log main;
sendfile on;
keepalive\_timeout 65;
gzip on;
server\_tokens off;
server {
listen 80;
server\_name localhost;
location / {
root html;
rewrite ^/(.\*) http://ip?/download redirect;
}
location ~\* ^/download {
root html;
autoindex on;
autoindex\_localtime on;
autoindex\_exact\_size off;
}
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章