基础使用
- 安装
brew install jenkins
- 启动服务
brew services start jenkins
- 停止服务
brew services stop jenkins
- 初始配置
open http://localhost:8080
- 解锁 Jenkins
cat $HOME/.jenkins/secrets/initialAdminPassword
- 更新
brew upgrade jenkins
- 卸载
brew uninstall jenkins --force
- 清除依赖
brew cleanup
配置自动化打包
-
General
1.png -
参数化构建过程
GIT_BRANCH
Git Parameter.png
origin/(.*)
Git Parameter.png
布尔值参数
4.png
-
源码管理
*/${GIT_BRANCH}
5.png Build Steps
cd ./Project/
export LANG=en_US.UTF-8
/opt/homebrew/bin/pod install
/opt/homebrew/bin/fastlane fir
$HOME/task/scripts/notice.sh "$JOB_BASE_NAME" "$GIT_BRANCH" "$SEND_TO_TEST" "$SEND_TO_UI"
Fastlane
default_platform(:ios)
platform :ios do
desc "upload ipa"
lane : pgyer do
gym(
clean:false,
scheme:"Project",
configuration:"Debug",
export_method:"development",
)
pgyer_key = "xxxx"
# 上传pgyer平台
pgyer(api_key: "#{pgyer_key}")
sh "./notice.sh"
end
lane :fir do
gym(
clean:false,
scheme:"Project",
configuration:"Debug",
export_method:"development",
)
firim_key = "xxxx"
# 上传firim平台
firim(firim_api_token: "#{firim_key}")
end
lane :build do
gym(
clean:false,
verbose: true,
scheme:"Project",
configuration:"Debug",
export_method:"development",
)
end
end
notice.sh
#!/bin/zsh
# 项目名称
readonly JOB_BASE_NAME=$1
# 打包分支
readonly GIT_BRANCH=$2
# 推送消息1
readonly SEND_TO_TEST=$3
# 推送消息2
readonly SEND_TO_UI=$4
# 设置本地仓库路径
GIT_REPO_PATH="$HOME/.jenkins/workspace/${JOB_BASE_NAME}"
# 最后一次提交信息
COMMIT_MSG=$(git -C "$GIT_REPO_PATH" log -1 --pretty=format:"%s")
APP_NAME="项目昵称"
APP_LINK="http://xxxx.com"
APP_QRCODE="http://api.xxxx.cn"
if [[ "$SEND_TO_TEST" = "true" ]]; then
# Webhook
TEST_WEBHOOK_URL="https://oapi.xxxx.com"
# 文本信息
TEST_MESSAGE='{
"msgtype": "markdown",
"markdown": {
"title":"发包通知",
"text":"### iOS【'${APP_NAME}'】发包通知🚀🚀🚀
\n 🌿 打包分支: '${GIT_BRANCH}'
\n ✏️ 最新提交: '${COMMIT_MSG}'
\n 🔗 [Download]('${APP_LINK}')
\n 
\n @user1 @user2"
},
"at": {
"atDingtalkIds": [
"user1",
"user2",
],
"isAtAll": false
}
}'
# 通过 curl 指令发送 Webhook 通知消息
curl -H "Content-Type: application/json" -X POST -d "$TEST_MESSAGE" "$TEST_WEBHOOK_URL"
fi
if [[ "$SEND_TO_UI" = "true" ]]; then
# Webhook
UI_WEBHOOK_URL="https://oapi.xxxx.com"
# 文本信息
UI_MESSAGE='{
"msgtype": "markdown",
"markdown": {
"title":"发包通知",
"text":"### iOS【'${APP_NAME}'】发包通知🚀🚀🚀
\n 🌿 打包分支: '${GIT_BRANCH}'
\n ✏️ 最新提交: '${COMMIT_MSG}'
\n 🔗 [Download]('${APP_LINK}')
\n 
\n @user1 @user2"
},
"at": {
"atDingtalkIds": [
"user1",
"user2",
],
"isAtAll": false
}
}'
# 通过 curl 指令发送 Webhook 通知消息
curl -H "Content-Type: application/json" -X POST -d "$UI_MESSAGE" "$UI_WEBHOOK_URL"
fi