创建项目
1、选择“构建一个自由风格的软件项目”,点击OK
2、构建->增加构建步骤“Execute shell”, 添加自己的脚本命令(最后有构建命令demo)
*配置构建可选参数
1、General->Choice
*构建触发器(定时发布)
Build periodically ->
00 0 * * *
00 12 * * *
25 17 * * *
语法说明:MINUTE HOUR DOM MONTH DOW
MINUTEMinutes within the hour (0-59)
HOURThe hour of the day (0-23)
DOMThe day of the month (1-31)
MONTHThe month (1-12)
DOWThe day of the week (0-7) where 0 and 7 are Sunday.
“ * * * ” EveryDay
*构建shell(android)
shell步骤介绍
1、定义目录与变量
2、svn upgrade + svn up
3、动态修改env.gradle
4、clean + build
5、sit&uat 打包并上传到svn目录
6、pro生产包(未加固):输出到目录/Users/xxx/Documents/android_build/releaseApk
7、pro自动备份mapping:/Users/xxx/Documents/android_build/mappingBackup
8、最后把最新包提交到项目的serApk目录 ,方便开发领取
#!/bin/sh
echo "你选择的编译环境是:"${Environment}
# shell步骤介绍
#1、定义目录与变量
#2、svn upgrade + svn up
#3、动态修改env.gradle
#4、clean + build
#5、sit&uat 打包并上传到svn目录
#6、pro生产包(未加固):输出到目录/Users/xxx/Documents/android_build/releaseApk
#7、pro自动备份mapping:/Users/xxx/Documents/android_build/mappingBackup
#8、最后把最新包提交到项目的serApk目录 ,方便开发领取
ROOTPATH="/xxx/appproject/android/河蟹的项目名"
MAIN_PROJECTPATH="$ROOTPATH/app"
GLOBAL_PATH=$ROOTPATH
CONFIG="env.gradle"
BANKNAME="xxxxx"
VERSION="1.0.0"
COPY_MAPPING="/Users/xxx/Documents/android_build/mappingBackup/$BANKNAME/$VERSION"
COPY_RELEASE_APK="/Users/xxx/Documents/android_build/releaseApk/$BANKNAME/$VERSION"
#
APPNAME="app-flavors_release"
if [ $Environment == "SIT" ]
then
MODE="test"
elif [ $Environment == "UAT" ]
then
MODE="uat"
elif [ $Environment == "GOLD" ]
then
MODE="gold"
else
MODE="pro"
fi
#此输出路径 一直拼错的,所以要提取此字段
ANDROID="andriod"
#MAC输出路径
APPPUBLISH_PATH_MAIN="/xxx/svnPackage/AppPublish/$BANKNAME"
APPPUBLISH_PATH="$APPPUBLISH_PATH_MAIN/$ANDROID/$MODE/"$VERSION
echo "----------输出路径:$APPPUBLISH_PATH----------"
cd $MAIN_PROJECTPATH
mkdir -p $APPPUBLISH_PATH
echo "----------工程svn update----------"
cd $ROOTPATH
svn upgrade
cd $ROOTPATH
svn up
cd $GLOBAL_PATH
if [ $Environment == "SIT" ]
then
sed -i '' 's/ENVIRONMENT = '".*"'/ENVIRONMENT = "sit"/g' $CONFIG
sed -i '' 's/SHOWLOG = '".*"'/SHOWLOG = "true"/g' $CONFIG
sed -i '' 's/SERVICEVERSION = '".*"'/SERVICEVERSION = "'$VERSION'"/g' $CONFIG
elif [ $Environment == "UAT" ]
then
sed -i '' 's/ENVIRONMENT = '".*"'/ENVIRONMENT = "uat"/g' $CONFIG
sed -i '' 's/SHOWLOG = '".*"'/SHOWLOG = "false"/g' $CONFIG
sed -i '' 's/SERVICEVERSION = '".*"'/SERVICEVERSION = "'$VERSION'"/g' $CONFIG
elif [ $Environment == "GOLD" ]
then
sed -i '' 's/ENVIRONMENT = '".*"'/ENVIRONMENT = "gold"/g' $CONFIG
sed -i '' 's/SHOWLOG = '".*"'/SHOWLOG = "false"/g' $CONFIG
sed -i '' 's/SERVICEVERSION = '".*"'/SERVICEVERSION = "'$VERSION'"/g' $CONFIG
else
sed -i '' 's/ENVIRONMENT = '".*"'/ENVIRONMENT = "pro"/g' $CONFIG
sed -i '' 's/SHOWLOG = '".*"'/SHOWLOG = "false"/g' $CONFIG
sed -i '' 's/SERVICEVERSION = '".*"'/SERVICEVERSION = "'$VERSION'"/g' $CONFIG
fi
echo -e "\n -------remove 86 ----------"
rm -rf "$GLOBAL_PATH/src/main/jniLibs/x86"
rm -rf "$GLOBAL_PATH/src/main/jniLibs/x86_64"
echo -e "\n-------移除ndk编译前代码 ----------"
echo "-------Cleaning ----------"
cd $MAIN_PROJECTPATH
source ~/.bash_profile
gradle clean
echo "-------Building ----------"
gradle build
echo "-------COPY ----------"
Filename=$BANKNAME"_"$(date +%Y%m%d)"_"$(date +%H%M)"_v"$VERSION"_"$MODE".apk"
RELEASE_APPPATH="$MAIN_PROJECTPATH/build/outputs/apk/$APPNAME-release.apk"
#删除上次生成的文件
#rm -rf $APPPUBLISH_PATH
if [ $Environment == "PRO" ]
then
#生产处理
mkdir -p $COPY_RELEASE_APK
cp -r $RELEASE_APPPATH $COPY_RELEASE_APK"/"$Filename
echo "####生产版本需手动加固:$COPY_RELEASE_APK/$Filename####"
#自动备份mapping文件
mkdir -p $COPY_MAPPING
MAPPING_PATH="$MAIN_PROJECTPATH/build/outputs/mapping/flavors_release/release/mapping.txt"
cp -r $MAPPING_PATH "$COPY_MAPPING/mapping_"$(date +%Y%m%d)".txt"
echo "#### mapping backup:'$MAPPING_PATH'"
else
#sit and uat
mkdir -p $APPPUBLISH_PATH
cp -r $RELEASE_APPPATH $APPPUBLISH_PATH"/"$Filename
cd $APPPUBLISH_PATH_MAIN
cd $ANDROID
svn add * --force
svn ci -m "committing app to svn......."
fi
echo "------copy to project path 不管什么环境,方便开发人员拿安装包-------"
PROJECTPATH=$ROOTPATH"/serApk"
echo "-----删除整个目录serApk 重新创建----"
rm -rf $PROJECTPATH
svn rm $PROJECTPATH
svn commit -m "Deleted file 'serApk'."
mkdir -p $PROJECTPATH
svn add $PROJECTPATH --force
svn ci $PROJECTPATH -m "create new serApk"
cp -r $RELEASE_APPPATH $PROJECTPATH"/"$Filename
cd $PROJECTPATH
svn add * --force
svn ci -m "committing app to svn......."
echo "-------Complete! ----------"
#jenkins 定时任务
#00 0 * * *
#00 12 * * *
#25 17 * * *
*evn.gradle参考
ext {
PKGNAME = "com.xxx.yyy"
/**
* SIT测试环境
* UAT用户环境
* PRO生产环境
* GOLD小额真金环境
*/
environment = [
SIT : "sit",
UAT : "uat",
PRO : "pro",
GOLD: "gold",
]
VERSIONCODE = 1
VERSIONNAME = "1.0.0"
ENVIRONMENT = "sit"
SHOWLOG = "true"
SERVICEVERSION = "1.0.0"
android = [
compileSdkVersion: 25,
buildToolsVersion: "25.0.2",
minSdkVersion : 14,
targetSdkVersion : 25,
]
}
*自定义BuildConfig变量(项目全局使用)
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {//项目默认配置
/**ENVIRONMENT枚举*/
buildConfigField "String", "ENUMSIT", "\"" + rootProject.ext.environment.SIT + "\""
buildConfigField "String", "ENUMUAT", "\"" + rootProject.ext.environment.UAT + "\""
buildConfigField "String", "ENUMPRO", "\"" + rootProject.ext.environment.PRO + "\""
/**BUIDLCONFIG 方式自动构建常量*/
buildConfigField "String", "ENVIRONMENT", "\"" + rootProject.ext.ENVIRONMENT + "\""
buildConfigField "boolean", "LOG_VISIBLE", rootProject.ext.SHOWLOG
buildConfigField "String", "SERVICE_VERSION", "\"" + rootProject.ext.SERVICEVERSION + "\""
buildConfigField "String", "RELEASETIME", "\"" + releaseTime() + "\""
applicationId rootProject.ext.PKGNAME
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.VERSIONCODE
versionName rootProject.ext.VERSIONNAME
multiDexEnabled true
ndk {
// 设置支持的SO库架构
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
}
}