1 安裝Jenkins
Jenkins是基于Java開發(fā)的一種持續(xù)集成工具腔丧。所以呢跃闹,要使用Jenkins必須使用先安裝JDK示辈。
JDK安裝:Java Development Kit
Jenkins安裝
注意: 1取胎、Jenkins 安裝成功后,會創(chuàng)建一個Jenkins用戶闽晦,而Jenkins的工作區(qū)間默認(rèn)是在【/用戶/共享/Jenkins/Home/jobs】目錄下劫窒,可以用Finder-->前往本今,進入。
2主巍、Jenkins目錄下的文件夾的讀寫權(quán)限只對Jenkins用戶開放诈泼,所以后面apple證書等必須在Jenkins用戶下安裝,項目的ipa導(dǎo)出也得在Jenkins用戶下操作煤禽。(或者用管理員權(quán)限修改該目錄針對用戶的權(quán)限)
3铐达、Jenkins的使用是每一個用戶都可以使用,所以有可能導(dǎo)致構(gòu)建版本的時候報錯檬果,還是老老實實在Jenkins用戶下操作吧瓮孙。
測試Jenkins安裝成功 會自動打開瀏覽器
如果出現(xiàn)下面情況,則JDK有問題重新安裝
下圖表明安裝成功
打開瀏覽器选脊,輸入http://localhost:8080杭抠,如果能夠正常打開Jenkins,則Jenkins安裝成功恳啥。
設(shè)置Jenkins用戶
2.1 進入 系統(tǒng)偏好設(shè)置->用戶與群組
2.2 點擊左下角的解鎖偏灿,輸入當(dāng)前用戶的密碼
2.3 此時Jenkins用戶還是一個空的無名用戶,可以在用戶列表中選擇Jenkins用戶钝的,右擊并選擇“高級選項”翁垂,輸入全名并確定。
2.4 **點擊“更改密碼”重設(shè)Jenkins用戶的密碼硝桩。為了后期方便沿猜,可勾選“運行用戶管理這臺電腦”,將Jenkins用戶設(shè)為管理員碗脊。 **
2.5 選擇用戶列表下方的登錄選項啼肩,將自動登錄用戶設(shè)為Jenkins。
3.初始化Jenkins
重啟以后,自動以Jenkins登錄了祈坠。找到/Users/Shared/Jenkins/Home/ 這個目錄下害碾,打開initialAdminPassword文件,復(fù)制出密碼赦拘,就可以填到網(wǎng)頁上去重置密碼了蛮原。
常用插件
Keychains and Provisioning Profiles Management
Post-Build Script Plug-in
SSH Slaves plugin
Subversion Tagging Plugin
GitLab Plugin
Extended Choice Parameter Plug-In
配置項目
配置代碼
echo "準(zhǔn)備開始打ipa包...................."
#項目名稱
project_name="HeiPiaoFishingBusiness"
#工程環(huán)境路徑
workspace_path="/Users/Shared/Jenkins/Home/workspace/IOS-B"
#build的路徑
build_path="$workspace_path/$project_name"
#證書
CODE_SIGN_IDENTITY="iPhone Distribution: Shenzhen Heipiao Technology Co., Ltd. (456PY4GRQJ)"
#描述文件
PROVISIONING_PROFILE_APPSTORE="eea7f8c4-08c8-459d-ae9d-9ca66a5e529b"
PROVISIONING_PROFILE_AD_Hoc="fc6bf319-0114-4c0b-8d1c-e9f90419ffe9"
#蒲公英USER_KEY
USER_KEY="7b19054ef2a2aa2678cddbd33d1b10d5"
#蒲公英API_KEY
API_KEY="cafcda0bf7a09201f1d39cb2965a2c6f"
svn upgrade
#解決沖突文件
svn resolve --accept theirs-full "${build_path}/${project_name}/Dev_info.plist"
# info.plist路徑
project_infoplist_path="$build_path/$project_name/Info.plist"
#取版本號
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
DATE="$(date +%y-%m-%d-%H-%M-%S)"
#IPA名
appName_appStore="${project_name}_V${bundleShortVersion}_${DATE}_appStore"
appName_productNetTest="${project_name}_V${bundleShortVersion}_${DATE}_productNetTest"
appName_outNetTest="${project_name}_V${bundleShortVersion}_${DATE}_outNetTest"
appName_inNetTest="${project_name}_V${bundleShortVersion}_${DATE}_inNetTest"
#.app生成后的路徑
app_path=$build_path/build/Build/Products/Release-iphoneos/${project_name}.app
app_Dev_path=$build_path/build/Build/Products/Release-iphoneos/${project_name}_Dev.app
#添加解鎖
security unlock-keychain -p "0" "/Users/Shared/Jenkins/Library/Keychains/login.keychain-db"
cd $workspace_path
log=$(svn log |head -n 5)
# >不追加輸出 >>追加輸出
echo $log > log.txt
mkdir -p APPS
#IPA生成后的路徑
ipa_appStore_path=$workspace_path/APPS/${appName_appStore}.ipa
ipa_productNetTest_path=$workspace_path/APPS/${appName_productNetTest}.ipa
ipa_outNetTest_path=$workspace_path/APPS/${appName_outNetTest}.ipa
ipa_inNetTest_path=$workspace_path/APPS/${appName_inNetTest}.ipa
echo "第一步,進入項目工程文件: $build_path"
cd $build_path
echo "第二步另绩,執(zhí)行build clean命令"
xcodebuild clean
#參數(shù)構(gòu)建
#內(nèi)網(wǎng)測試
if [ $para = "innet" ]; then
echo "第三步,執(zhí)行編譯生成.app命令"
xcodebuild -workspace $project_name.xcworkspace -scheme "${project_name}_Dev" -sdk iphoneos GCC_PREPROCESSOR_DEFINITIONS="DEVELOPMENT=1 API_TYPE=0" PROVISIONING_PROFILE="$PROVISIONING_PROFILE_AD_Hoc" CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" IPHONEOS_DEPLOYMENT_TARGET="8.0" -configuration Release -derivedDataPath build
echo "第四步, 導(dǎo)出ipa包"
xcrun -sdk iphoneos PackageApplication -v ${app_Dev_path} -o ${ipa_inNetTest_path}
echo "制作 outNetTest ipa 包完成......................."
#路徑寫入文件
#echo "${ipa_inNetTest_path}" > $workspace_path/path.txt
cd /Users/Shared/Jenkins/Home/workspace
./upload.sh ${ipa_inNetTest_path} ${log}
#外網(wǎng)測試
elif [ $para = "outnet" ]; then
echo "第三步花嘶,執(zhí)行編譯生成.app命令"
xcodebuild -workspace $project_name.xcworkspace -scheme "${project_name}_Dev" -sdk iphoneos GCC_PREPROCESSOR_DEFINITIONS="DEVELOPMENT=1 API_TYPE=1" PROVISIONING_PROFILE="$PROVISIONING_PROFILE_AD_Hoc" CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" IPHONEOS_DEPLOYMENT_TARGET="8.0" -configuration Release -derivedDataPath build
#echo "第四步, 導(dǎo)出ipa包"
xcrun -sdk iphoneos PackageApplication -v ${app_Dev_path} -o ${ipa_outNetTest_path}
echo "制作 outNetTest ipa 包完成......................."
#上傳外網(wǎng)測試包到蒲公英
echo '++++++++++++++upload+++++++++++++'
#路徑寫入文件
#echo "${ipa_outNetTest_path}" > $workspace_path/path.txt
cd /Users/Shared/Jenkins/Home/workspace
./upload.sh ${ipa_outNetTest_path} ${log}
else
#生成APPSTORE包
echo "第三步笋籽,執(zhí)行編譯生成.app命令"
xcodebuild -workspace $project_name.xcworkspace -scheme $project_name -sdk iphoneos GCC_PREPROCESSOR_DEFINITIONS="DEVELOPMENT=0 API_TYPE=2" PROVISIONING_PROFILE="$PROVISIONING_PROFILE_APPSTORE" CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" IPHONEOS_DEPLOYMENT_TARGET="8.0" -configuration Release -derivedDataPath build
echo "第四步, 導(dǎo)出ipa包"
xcrun -sdk iphoneos PackageApplication -v $app_path -o $ipa_appStore_path
echo "制作appStore ipa包完成......................."
#生產(chǎn)環(huán)境測試
echo "第二步,執(zhí)行build clean命令"
xcodebuild clean
echo "第三步椭员,執(zhí)行編譯生成.app命令"
xcodebuild -workspace $project_name.xcworkspace -scheme ${project_name} -sdk iphoneos GCC_PREPROCESSOR_DEFINITIONS="DEVELOPMENT=0 API_TYPE=2" PROVISIONING_PROFILE="$PROVISIONING_PROFILE_AD_Hoc" CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" IPHONEOS_DEPLOYMENT_TARGET="8.0" -configuration Release -derivedDataPath build
echo "第四步, 導(dǎo)出ipa包"
xcrun -sdk iphoneos PackageApplication -v ${app_path} -o ${ipa_productNetTest_path}
echo "制作 productNetTest ipa 包完成......................."
#路徑寫入文件
#echo "${ipa_productNetTest_path}" > $workspace_path/path.txt
cd /Users/Shared/Jenkins/Home/workspace
./upload.sh ${ipa_productNetTest_path} ${log}
if [ $tag = "true" ]; then
#tag
echo "打tag V${bundleShortVersion}_${DATE}"
svn cp -m "打tag V${bundleShortVersion}_${DATE}" https://192.168.1.201/svn/heipiao/app/ios/B/trunk/${project_name} https://192.168.1.201/svn/heipiao/app/ios/B/tags/V${bundleShortVersion}_${DATE}
fi
fi
upload.sh
代碼
#!/bin/sh
echo '==============='
echo $*
while result=$(curl --retry 10 -F "file=@$1" -F "uKey=7b19054ef2a2aa2678cddbd33d1b10d5" -F "_api_key=cafcda0bf7a09201f1d39cb2965a2c6f" -F "updateDescription=$2" "https://qiniu-storage.pgyer.com/apiv1/app/upload")
echo ${result}
do
if [[ $result == '' ]]; then
echo "upload fail"
else
echo "upload success"
break
fi
done
沒有Scheme车海,導(dǎo)致無法打包
命令行調(diào)用code sign時報錯
security unlock-keychain -p "你的用戶密碼" ~/Library/Keychains/login.keychain
Mac下Jenkins+SVN+Xcode構(gòu)建持續(xù)導(dǎo)出環(huán)境
Mac下Jenkins+SVN(Git)+Xcode搭建持續(xù)構(gòu)建環(huán)境
手把手教你利用Jenkins持續(xù)集成iOS項目
基于xcodebuild和xcrun的自動化打包
xcodebuild -sdk xxx -target xxx GCC_PREPROCESSOR_DEFINITIONS="API_TYPE=0"
API_TYPE=0 ,后面只能為數(shù)字 在下圖配置
基本配置
安卓配置
- 安卓shell腳本
#start
#項目名稱
PROJECT_NAME="Android_B"
#工程環(huán)境路徑
WORKSPACE_PATH="${JENKINS_HOME}/jobs/${PROJECT_NAME}/workspace"
#蒲公英USER_KEY
USER_KEY="7b19054ef2a2aa2678cddbd33d1b10d5"
#蒲公英API_KEY
API_KEY="cafcda0bf7a09201f1d39cb2965a2c6f"
# gradle.properties路徑
VERSION_CODE_PATH="${WORKSPACE_PATH}/gradle.properties"
#取版本號
VERSION_CODE=`cat ${VERSION_CODE_PATH} | sed -n 's/.*VERSION_NAME=\(\S\)/\1/p' | tr -d '\r'`
echo ${VERSION_CODE}
#時間
DATE="$(date +%Y-%m-%d)"
#svn路徑
SVN_TAG_PATH="https://192.168.1.201/svn/heipiao/app/andriod/B/tags"
#trunk_path
TRUNK_PATH="https://192.168.1.201/svn/heipiao/app/andriod/B/trunk"
SVN_USER="maimingliang"
SVN_PWD="maimingliang"
#tagName
TAG_NAME="v${VERSION_CODE}-${DATE}"
echo ${TAG_NAME}
if [ ${BUILD_TYPE} = 'ProductionRelease' ]&&[ ${IS_CREATE_TAG} = 'true' ]; then
echo "創(chuàng)建tag目錄"
svn mkdir ${SVN_TAG_PATH}/${TAG_NAME} -m "mkdir tags ${TAG_NAME}" --username "$SVN_USER" --password "$SVN_PWD" --non-interactive
echo "打tag"
svn cp $TRUNK_PATH $SVN_TAG_PATH/${TAG_NAME} -m "tag version ${TAG_NAME}-${DATE}" --username "$SVN_USER" --password "$SVN_PWD" --non-interactive
else
echo '不符合打tag的條件'
fi
#日志
LOG_STR=$(svn log --limit 1 --username=$SVN_USER --password=$SVN_PWD ${WORKSPACE_PATH})
echo ${LOG_STR}
#判斷是否需要上傳蒲公英
if [ ${BUILD_TYPE} = 'BetaOutdebug' ]; then
curl --retry 10 -F "file=@${WORKSPACE_PATH}/app/build/outputs/apk/hp-b-v${VERSION_CODE}-beta-${DATE}-outdebug.apk" -F "uKey=${USER_KEY}" -F "_api_key=${API_KEY}" https://qiniu-storage.pgyer.com/apiv1/app/upload
else
echo ${BUILD_TYPE}
fi
#判斷是否需要打tag
#end