Skip to content

Instantly share code, notes, and snippets.

@CFM880
Created July 6, 2019 12:18
Show Gist options
  • Save CFM880/54953ec558cfb829c50a511db87e0bc6 to your computer and use it in GitHub Desktop.
Save CFM880/54953ec558cfb829c50a511db87e0bc6 to your computer and use it in GitHub Desktop.
teamcity Android build shell
#!/usr/bin/env bash
git_hash=kkkk
if [ -z $git_hash ];
then
echo "$i 是空字符串"
else
git reset --hard ${git_hash}
fi
#!/usr/bin/env bash
build_type=%build_type%
product_flavors=(%flavors%)
is_open_sense=%is_open_sensorsdata%
version_code=%version_code%
version_name=%version_name%
#build_type=release
#product_flavors=(a6s a5)
#is_open_sense=false
#version_code=52
#version_name=v1.234
export ANDROID_HOME=/data/teamcity-agent/android-sdk-linux
export PATH=$PATH:/data/teamcity-agent/android-sdk-linux/tools
export PATH=$PATH:/data/teamcity-agent/android-sdk-linux/platform-tools
cp /data/teamcity-agent/env/keystore.jks ./
echo "===================开始清理========================="
./gradlew clean
echo "===================清理完成========================="
current_path=$PWD
rm -rf %teamcity.build.checkoutDir%/cos.html
echo "<h2>apk list</h2></br>" >> cos.html
### for send message to wechat_msg
changes=`git log --pretty=format:"%h %s commit %cn" -1`
device_types=""
#########################################################
for(( i=0;i<${#product_flavors[@]};i++));
do
device_type="${product_flavors[i]}"
device_types=${device_types}" "${device_type}
echo "编译类型:${build_type} 设备:${device_type} versionCode:${version_code} versionName: ${version_name}"
echo "===============start build ${device_type}==============="
echo "./gradlew assemble${device_type}${build_type} -P stage=${build_type} -P spaxVersionName=${version_name} -P spaxVersionCode=${version_code} -P spaxDeviceName=${device_type} -P isOpenSensorsdata=${is_open_sense}"
rm -rf app/build/outputs/apk/${device_type}/${build_type}/*
# 执行的编译命令
./gradlew assemble${device_type}${build_type} -P stage=${build_type} -P spaxVersionName=${version_name} -P spaxVersionCode=${version_code} -P spaxDeviceName=${device_type} -P isOpenSensorsdata=${is_open_sense}
# 上传
####################### upload
apk_file_name=`cd app/build/outputs/apk/${device_type}/${build_type} && ls *.apk && cd ${current_path}`
echo ${apk_file_name}
apk_file_path=app/build/outputs/apk/${device_type}/${build_type}/*.apk
echo ${apk_file_path}
coscmd upload ${apk_file_path} /artifacts/spax-os/${build_type}/${version_name}/$device_type/%build.number%-${apk_file_name}
upload_url="https://xxxxxx.myqcloud.com/artifacts/xxxx/${build_type}/${version_name}/$device_type/%build.number%-${apk_file_name}"
echo "<a href=""$upload_url"">${device_type} ${build_type} download link</a></br>" >> cos.html
echo "upload !"
done
title="spax-os ${build_type} ${device_types} build success"
curl -X POST \
http://xxxxx/admin/wechat_msg \
-H "content-type: multipart/form-data" \
-H "x-access-token: token" \
-F "url=http://xxxxxxxx/repository/download/SpaxLauncher_BuildUpgrade/%teamcity.build.id%:id/cos.html" \
-F "title=$title" \
-F "content=$changes" \
-F "image=https://xxxxxx/uploads/images/inforOS.jpg" \
-F "group_id=12052195555496902744"
# 移动文件
# build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment