基礎使用
- 安裝
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 參數
Git Parameter.png
Git Parameter.png
布爾值參數
4.png
-
源碼管理
5.png
-
Environment
6.png Build Steps
cd ./Project/
export LANG=en_US.UTF-8
/opt/homebrew/bin/pod install
/opt/homebrew/bin/fastlane build
$HOME/task/scripts/upload_ipa.sh "$JOB_NAME" "$GIT_BRANCH" "debug" "$BUILD_NUMBER" "appstore" "$SEND_TO_PM_UI"
Fastlane
default_platform(:ios)
platform :ios do
desc "uploaded pgyer"
lane :dev do
gym(
clean:false,
scheme:"Project",
configuration:"Debug",
export_method:"development",
)
api_key = "xxxx"
pgyer(api_key: "#{api_key}")
sh "./notice.sh"
end
lane :build do
gym(
clean:false,
scheme:"Project",
configuration:"Debug",
export_method:"development",
)
end
end
notice.sh
#!/bin/bash
# Webhook
WEBHOOK_URL="xxxx"
# 文本信息
MESSAGE='{
"msgtype": "markdown",
"markdown": {
"title":"發包通知??????",
"text":"**春江水暖,本鴨先知** ??
\r **iOS 測試包**
\r [?? Download](xxxx)
\r "
}
}'
MESSAGEAT='{
"msgtype": "text",
"text": {
"content": "??????iOS發包通知 @139xxxx @176xxxx"
},
"at": {
"atMobiles": [
"139xxxx",
"176xxxx"
],
"atUserIds": [
"xxxx",
"xxxx",
],
"isAtAll": false
},
}'
# 通過 curl 指令發送 Webhook 通知消息
curl -H "Content-Type: application/json" -X POST -d "$MESSAGE" "$WEBHOOK_URL"
# 通過 curl 指令發送 Webhook @消息
curl -H "Content-Type: application/json" -X POST -d "$MESSAGEAT" "$WEBHOOK_URL"
upload_ipa.sh
#!/bin/zsh
# ---------------------------------------------------------------
# functions
# ---------------------------------------------------------------
# 小黃鴨 token
WEBHOOK_URL_XHY="xxxx"
# 打包小助手 token
WEBHOOK_URL_DBXZS="xxxx"
# 測試 token
WEBHOOK_URL_TEST="xxxx"
#給UI驗收 -BK
WEBHOOK_URL_UI_BK="xxxx"
#給UI驗收 -SC
WEBHOOK_URL_UI_SC="xxxx"
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"
}
logTitle() {
log "-------------------------------- $* --------------------------------"
}
execCommand() {
log "$@"
result=$(eval $@)
}
sendMsg() {
if [ "$JOB_NAME" = "iOS_BK_DEV" ]; then
# ---------------------------------------------------------------
# 上傳到fir
# ---------------------------------------------------------------
logTitle "上傳到fir"
/opt/homebrew/opt/ruby/bin/fir publish $IPA_ABS_PATH -T xxxxxx
# 要發送的消息內容
MESSAGE='{"msgtype": "markdown", "markdown": {"title": "Jenkins打包完成", "text": "
\r\n ### 發包通知:'$APP_NAME'iOS 打包完成
\r\n > 打包分支: '${GIT_BRANCH}'
\r\n > 最新提交: '${COMMIT_MSG}'
\r\n 打包完成,請掃碼下載!
\r\n 
\r\n @176xxxx @139xxxx"}
, "at": {
"atMobiles": [
"176xxxx",
"139xxxx"
],
"atUserIds": [
"xxxx",
"xxxx"
],
"isAtAll": false
}
}'
# 發送POST請求到釘釘Webhook
curl -H "Content-Type: application/json" -X POST -d "$MESSAGE" "$WEBHOOK_URL_XHY"
if [[ "$SEND_TO_PM_UI" = "true" ]]; then
# 要發送的消息內容
MESSAGE='{"msgtype": "markdown", "markdown": {"title": "Jenkins打包完成", "text": "
\r\n ### 發包通知:'$APP_NAME'iOS 打包完成
\r\n > 打包分支: '${GIT_BRANCH}'
\r\n > 最新提交: '${COMMIT_MSG}'
\r\n 打包完成,請掃碼下載!
\r\n 
\r\n @136xxxx6 @158xxxx @136xxxx"}
, "at": {
"atMobiles": [
"136xxxx",
"158xxxx",
"136xxxx"
],
"atUserIds": [
"xxxx",
"xxxx",
"xxxx"
],
"isAtAll": false
}
}'
# 發送POST請求到釘釘Webhook
curl -H "Content-Type: application/json" -X POST -d "$MESSAGE" "$WEBHOOK_URL_UI_BK"
fi
else
# ---------------------------------------------------------------
# 上傳到fir
# ---------------------------------------------------------------
logTitle "上傳到fir"
/opt/homebrew/opt/ruby/bin/fir publish $IPA_ABS_PATH -T xxxxxxxx
# 要發送的消息內容
MESSAGE='{"msgtype": "markdown", "markdown": {"title": "Jenkins打包完成", "text": "
\r\n ### 發包通知:'$APP_NAME'iOS 打包完成
\r\n > 打包分支: '${GIT_BRANCH}'
\r\n 打包完成,請掃碼下載!
\r\n 
\r\n @158xxxx"}
, "at": {
"atMobiles": [
"158xxxx"
],
"atUserIds": [
"xxxx"
],
"isAtAll": false
}
}'
# 發送POST請求到釘釘Webhook
curl -H "Content-Type: application/json" -X POST -d "$MESSAGE" "$WEBHOOK_URL_DBXZS"
if [[ "$SEND_TO_PM_UI" = "true" ]]; then
# 要發送的消息內容
MESSAGE='{"msgtype": "markdown", "markdown": {"title": "Jenkins打包完成", "text": "
\r\n ### 發包通知:'$APP_NAME'iOS 打包完成
\r\n > 打包分支: '${GIT_BRANCH}'
\r\n 打包完成,請掃碼下載!
\r\n 
\r\n @136xxxx @176xxxx @176xxxx"}
, "at": {
"atMobiles": [
"136xxxx",
"176xxxx",
"176xxxx"
],
"atUserIds": [
"xxxx",
"xxxx",
"xxxx"
],
"isAtAll": false
}
}'
# 發送POST請求到釘釘Webhook
curl -H "Content-Type: application/json" -X POST -d "$MESSAGE" "$WEBHOOK_URL_UI_SC"
fi
fi
}
# 名字
readonly JOB_NAME=$1
# 分支
readonly GIT_BRANCH=$2
# 編譯類型
readonly BUILD_TYPE=$3
# 構建編號
readonly BUILD_NUMBER=$4
# 渠道
readonly BUILD_CHANNEL=$5
# 發給UI驗收
readonly SEND_TO_PM_UI=$6
logTitle "$SEND_TO_PM_UI"
# 當前時間
curlTime=`date +%Y%m%d_%H%M%S`
# ip 地址
ip=`ipconfig getifaddr en0`
APP_NAME=""
IPA_ABS_PATH=""
if [ "$JOB_NAME" = "iOS_BK_DEV" ]; then
APP_NAME="項目1"
IPA_ABS_PATH=$HOME/.jenkins/workspace/iOS_BK_DEV/BuildCard/Project.ipa
else
APP_NAME="項目2"
IPA_ABS_PATH=$HOME/.jenkins/workspace/iOS_SC_DEV/NFT/NFT.ipa
fi
# 打包地址
JOB_URL="http://$ip:8080/job/${JOB_NAME}/${BUILD_NUMBER}"
COMMIT_MSG=$(/usr/bin/git log -1 --pretty=format:"%s")
log COMMIT_MSG
# ---------------------------------------------------------------
# 發送消息推送
# ---------------------------------------------------------------
logTitle "發送釘釘消息"
sendMsg