1. jenkins 一定要命令行安装,不要官网下载安装包(不然后面各种权限问题弄的你想吐),安装各种插件
2. 前往 /资源库/LaunchDaemons/org.jenkins-ci.plist 修改GroupName和UserName 为当前用户的组和名字
3. 启动命令 java -jar /usr/local/Cellar/jenkins/2.117/libexec/jenkins.war --httpPort=8080
4.新建工程,配置shell命令
(IOS)命令
#<------------------------------------------------------->
# 删除旧源码目录->新建源码目录->从svn导出最新代码->清理旧文件->清除旧项目->打包->上传
pwd
# 名称配置
checkout_name="ios"
project_name="EasyPrice"
# 配置项目版本
targetProject_destination="generic/platform=iOS"
configuration="Release"
#configuration="Debug"
scheme="$project_name"
workspace_name="${project_name}.xcworkspace"
# 目录配置
save_path="/Users/august/Desktop/project_package/$project_name"
archive_path="$save_path/${project_name}.xcarchive"
ipa_path="$save_path/${project_name}.ipa"
log_path="$save_path/log.txt"
optionlist="$save_path/ExportOptions.plist"
# svn配置
svn_path="svn路径"
checkout_path="$save_path/$project_name"
svn_name="svn用户名"
svn_password="svn密码"
# 配置签名证书、描述文件
codeSignIdentity="签名文件名字"
provision_UUID="描述文件uuid"
provisoning_profile="描述文件名字"
# 配置蒲公英
#upload_path="$save_path/${project_name}.ipa"
upload_path="$ipa_path/${project_name}.ipa"
pgy_userKey="蒲公英userKey"
pgy_apiKey="蒲公英apiKey"
echo "正在删除旧源码"
# 删除旧源码目录
# rm -rf "$checkout_path" >> $log_path
echo "正在创建新的源码目录"
# 新建源码目录
# cd "$save_path" >> $log_path
pwd
#mkdir "$checkout_name" >> $log_path
echo "正在从svn下载最新的源码"
# 从svn导出最新代码
svn checkout "$svn_path" "$save_path" --username "$svn_name" --password "$svn_password" >> $log_path
#svn update "$checkout_path" --username "$svn_name" --password "$svn_password"
echo "正在删除旧文件"
# 删除旧文件
rm -rf "$log_path" >> $log_path
rm -rf "$archive_path" >> $log_path
rm -rf "$ipa_path" >> $log_path
echo "正在清除构建项目缓存"
# 重要,执行xcodebuild命令时,必须进入项目目录
cd "$checkout_path" >> $log_path
pwd
# 清理构建目录
xcodebuild clean -configuration "$configuration" -alltargets >> $log_path
echo "正在打包"
# 归档(其他参数不指定的话,默认用的是.xcworkspace或.xcodeproj文件里的配置)
xcodebuild archive -workspace "$workspace_name" -scheme "$scheme" -destination "$targetProject_destination" -configuration "$configuration" -archivePath "$archive_path"
echo "正在导出ipa包"
# 导出IPA
xcodebuild -exportArchive -archivePath "$archive_path" -exportPath "$ipa_path" -exportOptionsPlist "$optionlist"
echo "正在上传ipa到蒲公英"
# 上传IPA到蒲公英
curl -F "file=@$upload_path" -F "uKey=$pgy_userKey" -F "_api_key=$pgy_apiKey" https://qiniu-storage.pgyer.com/apiv1/app/upload
#<------------------------------------------------------->
//注意:ExportOptions.plist文件为手动打包,导出ipa文件时附带的,加入自己工程上层文件夹(可以自己指定文件夹),provisoning_profile(ad_hoc_Provisioning.mobileprovision)描述文件和工程文件放在一起
(android)命令
#<------------------------------------------------------->
# 删除旧源码目录->新建源码目录->从svn导出最新代码->清理旧文件->清除旧项目->打包->上传
pwd
project_name="Yijia"
# 目录配置
save_path="/Users/august/Desktop/project_package/EasyPrice_Android"
buildPath="/Users/august/Desktop/project_package/EasyPrice_Android/Yijia/app/build/outputs/apk/release"
log_path="$save_path/log.txt"
# svn配置
svn_path="svn自己填写"
checkout_path="$save_path/$project_name"
svn_name="svn自己填写"
svn_password="svn自己填写"
# 配置蒲公英
#upload_path="$save_path/${project_name}.ipa"
upload_path="$buildPath/app-release.apk"
pgy_userKey="蒲公英userKey自己填写"
pgy_apiKey="蒲公英apiKey自己填写"
echo "正在删除旧源码"
echo "delete doc $checkout_path"
# 删除旧源码目录
#log.txt如果没有请先创建
rm -rf "$log_path" >> $log_path
rm -rf "$checkout_path" >> $log_path
echo "正在创建新的源码目录"
# 新建源码目录
cd "$save_path" >> $log_path
pwd
mkdir "$project_name" >> $log_path
echo "正在从svn下载最新的源码"
# 从svn导出最新代码
svn checkout "$svn_path" "$checkout_path" --username "$svn_name" --password "$svn_password" >> $log_path
echo "正在清除构建项目缓存"
cd "$checkout_path" >> $log_path
// 添加执行权限
chmod +x gradlew
#开始打包
./gradlew assembleRelease
echo "正在上传工程文件到蒲公英"
# 上传IPA到蒲公英
curl -F "file=@$upload_path" -F "uKey=$pgy_userKey" -F "_api_key=$pgy_apiKey" https://qiniu-storage.pgyer.com/apiv1/app/upload
#<------------------------------------------------------->
注意:安卓打包可能会如果要加上证书的话,在工程的gradle.properties加入
RELEASE_STORE_FILE=签名文件地址
//RELEASE_STORE_FILE=/Users/august/Desktop/project_package/EasyPrice_Android/yijia.jks
RELEASE_STORE_PASSWORD=签名文件密码
RELEASE_KEY_ALIAS=文件别名
RELEASE_KEY_PASSWORD=文件别名密码
并在app下的build.gradle的android模块加入
signingConfigs {
debug {
storeFile file (RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
可完成证书打包
参考文章
Mac中jenkins的使用——自动构建
mac下Jenkins 主目录导致的权限问题