基礎(chǔ)使用
- 安裝
brew install jenkins
- 啟動服務(wù)
brew services start jenkins
- 停止服務(wù)
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 -
參數(shù)化構(gòu)建過程
GIT_BRANCH
Git Parameter.png
origin/(.*)

Git Parameter.png
布爾值參數(shù)

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
# 項(xiàng)目名稱
readonly JOB_BASE_NAME=$1
# 打包分支
readonly GIT_BRANCH=$2
# 推送消息1
readonly SEND_TO_TEST=$3
# 推送消息2
readonly SEND_TO_UI=$4
# 設(shè)置本地倉庫路徑
GIT_REPO_PATH="$HOME/.jenkins/workspace/${JOB_BASE_NAME}"
# 最后一次提交信息
COMMIT_MSG=$(git -C "$GIT_REPO_PATH" log -1 --pretty=format:"%s")
APP_NAME="項(xiàng)目昵稱"
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":"發(fā)包通知",
"text":"### iOS【'${APP_NAME}'】發(fā)包通知??????
\n ?? 打包分支: '${GIT_BRANCH}'
\n ?? 最新提交: '${COMMIT_MSG}'
\n ?? [Download]('${APP_LINK}')
\n 
\n @user1 @user2"
},
"at": {
"atDingtalkIds": [
"user1",
"user2",
],
"isAtAll": false
}
}'
# 通過 curl 指令發(fā)送 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":"發(fā)包通知",
"text":"### iOS【'${APP_NAME}'】發(fā)包通知??????
\n ?? 打包分支: '${GIT_BRANCH}'
\n ?? 最新提交: '${COMMIT_MSG}'
\n ?? [Download]('${APP_LINK}')
\n 
\n @user1 @user2"
},
"at": {
"atDingtalkIds": [
"user1",
"user2",
],
"isAtAll": false
}
}'
# 通過 curl 指令發(fā)送 Webhook 通知消息
curl -H "Content-Type: application/json" -X POST -d "$UI_MESSAGE" "$UI_WEBHOOK_URL"
fi


