系統(tǒng)環(huán)境
Mac OS 10.15.6
Xcode 12.4
安裝Jenkins
macOS Installers for Jenkins LTS
按官網步驟用命令行安裝:
brew install jenkins-lts
如果顯示Updating Homebrew...卡太久璃诀,就用Control+C跳過程剥,過會就會開始下載
Updating Homebrew...
^C==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openjdk%401
Already downloaded: /Users/${UserName}/Library/Caches/Homebrew/downloads/fb20efadec6110a61cc259dad9bc0ea16c12ad32e0d778578354d2d8166fc674--openjdk@11-11.0.8.catalina.bottle.tar.gz
==> Downloading http://mirrors.jenkins.io/war-stable/2.249.1/jenkins.war
==> Downloading from http://ftp-chi.osuosl.org/pub/jenkins/war-stable/2.249.1/je
######################################################################## 100.0%
==> Installing dependencies for jenkins-lts: openjdk@11
==> Installing jenkins-lts dependency: openjdk@11
==> Pouring openjdk@11-11.0.8.catalina.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
==> Summary
?? /usr/local/Cellar/openjdk@11/11.0.8: 650 files, 295.3MB
==> Installing jenkins-lts
==> /usr/local/opt/openjdk@11/bin/jar xvf jenkins.war
==> Caveats
Note: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login:
brew services start jenkins-lts
Or, if you don't want/need a background service you can just run:
jenkins-lts
==> Summary
?? /usr/local/Cellar/jenkins-lts/2.249.1: 7 files, 67.3MB, built in 6 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/${UserName}/Library/Logs/Homebrew/lame... (64B)
Removing: /Users/${UserName}/Library/Logs/Homebrew/wget... (64B)
Removing: /Users/${UserName}/Library/Logs/Homebrew/libpng... (64B)
Removing: /Users/${UserName}/Library/Logs/Homebrew/sox... (64B)
Removing: /Users/${UserName}/Library/Logs/Homebrew/mad... (64B)
Removing: /Users/${UserName}/Library/Logs/Homebrew/opusfile... (64B)
==> Caveats
==> openjdk@11
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
==> jenkins-lts
Note: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login:
brew services start jenkins-lts
Or, if you don't want/need a background service you can just run:
jenkins-lts
安裝成功帆赢,啟動jenkins-lts:
brew services start jenkins-lts
家里WiFi連不太上Github嫂粟,報如下錯誤:
fatal: unable to access 'https://github.com/Homebrew/homebrew-services/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-services /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services --origin=origin` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/services` exited with 1.
于是連手機4G熱點衙传,很快就成功了:
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 1149 (delta 12), reused 8 (delta 8), pack-reused 1121
Receiving objects: 100% (1149/1149), 334.35 KiB | 256.00 KiB/s, done.
Resolving deltas: 100% (488/488), done.
Tapped 1 command (41 files, 424.0KB).
==> Successfully started `jenkins-lts` (label: homebrew.mxcl.jenkins-lts)
Jenkins后臺配置
服務啟動成功后吟吝,在瀏覽器中打開 http://localhost:8080
按提示到該路徑復制密碼并粘貼
點擊`安裝推薦的插件`即開始自動安裝
等待安裝完成
安裝完成后,創(chuàng)建第一個管理員用戶菩佑,保存并完成
實例配置自晰,保存并完成
Jenkins已就緒!開始使用Jenkins
Jenkins主面板
安裝插件
安裝以下插件:
- Keychains and Provisioning Profiles Management(密鑰鏈和配置文件管理)
Keychains and Provisioning Profiles Management
上傳鑰匙串及配置文件
-
安裝完Keychains and Provisioning Profiles Management插件后稍坯,可在“系統(tǒng)管理”底部找到該插件酬荞,點擊進入配置:
安裝完該插件后,可在“系統(tǒng)管理”底部找到該插件劣光,點擊 準備文件
- 鑰匙串文件路徑:
~/Library/Keychains/login.keychain-db
- 配置文件路徑:
~/Library/MobileDevice/Provisioning Profiles/
- 上傳文件
本地Keychain文件后綴導游-db袜蚕,直接上傳是無效的糟把,需要把 login.keychain-db復制出來重命名去掉后綴-db绢涡,然后上傳。
Password:輸入本機密碼遣疯。
Code Signing Identity:去鑰匙串找到開發(fā)者證書名稱并填寫雄可。
Provisioning Profiles Directory Path:填寫默認路徑(注意將
${UserName}
替換成你Mac的用戶名):/Users/${UserName}/Library/MobileDevice/Provisioning Profiles
上傳鑰匙串及配置文件,然后Save
新建構建任務
不通版本的Jenkins的漢化程度不一樣缠犀,中英文混雜数苫,自己理解。
輸入任務名辨液,選擇構建一個自由風格的項目虐急,確定
添加Git倉庫地址,指定分支
點擊添加-Jenkins滔迈,可以通過賬號密碼或ssh來登錄git
勾選這兩項止吁,點擊保存,再回來這里就會自動填充內容
構建腳本
如果用到cocoapods
,要注意將-project
和.xcodeproj
改為-workspace
和.xcworkspace
還要在編譯前執(zhí)行pod install --verbose --no-repo-update
# 自定義變量
USE_COCOAPODS=false
# 編譯參數
BUILD_CONFIGURATION="DEBUG"
# 生成時間
BUILD_TIME=$(date +%Y%m%d_%H-%M-%S)
# 名稱
USER_NAME="xxxx"
PROJECT_NAME="CSSphinx"
TARGET_NAME="CSSphinxExample"
# 蒲公英Key
PGY_USER_KEY="xxxx"
PGY_API_KEY="xxxx"
# Path
INFO_PLIST_PATH="./${TARGET_NAME}/Info.plist"
PROJECT_PATH="/Users/${USER_NAME}/.jenkins/workspace/${PROJECT_NAME}"
OUTPUT_PATH="${PROJECT_PATH}/output/${BUILD_TIME}"
EXPORT_PATH="${OUTPUT_PATH}/${TARGET_NAME}"
ARCHIVE_PATH="${OUTPUT_PATH}/${TARGET_NAME}.xcarchive"
EXPORT_OPTIONS_PATH="${ARCHIVE_PATH}/Info.plist"
# 進入工程目錄
cd ${PROJECT_PATH}
# 清空工程
xcodebuild clean
#xcodebuild clean -project ${PROJECT_NAME}.xcodeproj -scheme ${TARGET_NAME} -configuration ${BUILD_CONFIGURATION}
# 生成xcarchive
if [ "$USE_COCOAPODS" == true ]; then
pod install --verbose --no-repo-update
xcodebuild archive -workspace ${PROJECT_NAME}.xcworkspace -scheme ${TARGET_NAME} -configuration release -archivePath ${ARCHIVE_PATH}
else
xcodebuild archive -project ${PROJECT_NAME}.xcodeproj -scheme ${TARGET_NAME} -configuration release -archivePath ${ARCHIVE_PATH}
fi
# 導出ipa包
xcodebuild -exportArchive -archivePath ${ARCHIVE_PATH} -exportPath ${EXPORT_PATH} -exportOptionsPlist ${EXPORT_OPTIONS_PATH}
# 上傳蒲公英
curl -F "file=@${EXPORT_PATH}/${TARGET_NAME}.ipa" -F "uKey=${PGY_USER_KEY}" -F "_api_key=${PGY_API_KEY}" https://qiniu-storage.pgyer.com/apiv1/app/upload
增加構建步驟-執(zhí)行shell-添加構建腳本
點擊立即構建宽菜,如果顯示紅色辅愿,則點擊該構建流水進入查看錯誤日志