系统环境
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
安装插件
安装以下插件:
- Keychains and Provisioning Profiles Management(密钥链和配置文件管理)
上传钥匙串及配置文件
-
安装完Keychains and Provisioning Profiles Management插件后,可在“系统管理”底部找到该插件,点击进入配置:
准备文件
- 钥匙串文件路径:
~/Library/Keychains/login.keychain-db
- 配置文件路径:
~/Library/MobileDevice/Provisioning Profiles/
- 上传文件
本地Keychain文件后缀导游-db,直接上传是无效的,需要把 login.keychain-db复制出来重命名去掉后缀-db,然后上传。
Password:输入本机密码。
Code Signing Identity:去钥匙串找到开发者证书名称并填写。
Provisioning Profiles Directory Path:填写默认路径(注意将
${UserName}
替换成你Mac的用户名):/Users/${UserName}/Library/MobileDevice/Provisioning Profiles
新建构建任务
不通版本的Jenkins的汉化程度不一样,中英文混杂,自己理解。
构建脚本
如果用到cocoapods
,要注意将-project
和.xcodeproj
改为-workspace
和.xcworkspace
还要在编译前执行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