前言
最近想在自己的电脑上安装Jenkins
用来打包,在此记录一下踩过的坑,首先我按照Jenkins
官网安装的
jenkins官网
homebrew
终端敲了几句命令,就成功安装了,但是到了上传证书那步,upload
没有反应,后来看见有人说是新版的bug,当前版本为v.2.303.2
, 2.263.4
版本没有这个bug,于是我按照官网的第二句下载指定版本
$brew install jenkins-lts@YOUR_VERSION
报错,于是我开始尝试其他途径,2.263.4
版本Jenkins.war
这里提供两种下载方式
1.手动下载jenkins.war
,解压安装
下载地址:
2.使用wget来下载
$wget https://get.jenkins.io/war-stable/2.263.4/jenkins.war
Java 8下载地址
下载安装启动以后会在 系统偏好设置 的最下面看见java的图标
其实手动下载和使用命令下载都是一样的
对于喜欢可视化的人可以使用手动下载
$ java -jar /Users/用户名/Desktop/jenkins/soft/jenkins.war
/Users/maxiaoliao/Desktop/jenkins/soft/jenkins.war: 2.263.4jenkins.war 目录
maxiaoliao@maxiaoliaodeMacBook-Pro-2 ~ % java -jar /Users/maxiaoliao/Desktop/jenkins/soft/jenkins.war
Running from: /Users/maxiaoliao/Desktop/jenkins/soft/jenkins.war
webroot: $user.home/.jenkins
...
Please use the following password to proceed to installation:
538397e5e63240b58d155fb43c70a1c2
This may also be found at: /opt/jenkins/2.263.4/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
538397e5e63240b58d155fb43c70a1c2 是初始密码
路径 Manage Jenkins -> Manage Plugins
这里我们下载两个插件 ,可选插件
一个用于上传证书和描述文件:Keychains and Provisioning Profiles Management
一个用于构建参数:Git Parameter
安装后可以重启一下,不是必须的
路径 Manage Jenkins
-> Keychains and Provisioning Profiles Management
⚠️:之前就是这个页面的upload
怎么都不好使###### 1).上传我们的keychain
和描述文件
keychain路径:~/Library/Keychains
描述文件路径:/Users/用户名/Library/MobileDevice/Provisioning Profiles
login.keychain-db
的文件 复制出来删掉-db
,文件名为login.keychain
upload
上传login.keychain
描述文件路径 /Users/用户名/Library/MobileDevice/Provisioning Profiles
然后保存,证书就配置好了
新建Item
-> 输入任务名
-> Freestyle project
-> 确定
是否已经存在本地公钥
$ cat ~/.ssh/id_rsa.pub
没有的话
$ ssh-keygen -t rsa -C "用户名"
会要求输入密码 如果不设置的 直接点击空格
查看公钥 从ssh-开始直到你的用户名和主机名为止的内容
$ cat ~/.ssh/id_rsa.pub
Mac复制
$ pbcopy < ~/.ssh/id_rsa.pub
查看私钥
$ cat ~/.ssh/id_rsa
以上一般满足不了我们需求,我们还需要一些配置,列举一些我需要的配置
Git Parameter
这个可以用来拉取 选择分支
下面的源码管理Branches to build
指定分支(为空时代表any) $branch
切换环境
#!/bin/sh
export LANG=en_US.UTF-8
# 根据Build选择
# 配置 APIEnvironment
PROJECT_PATH="项目本地目录"
SETTING_PATH="放adhoc.plist等的文件"
file="${PROJECT_PATH}/切换环境的文件"
config_str="var apiConfig: APIEnvironment = .${api_request}"
sed -i "" "20s/.*/$config_str/" "$file"
# 配置 Settings.Bundle
settings_bundle="${PROJECT_PATH}/Enterprise/Enterprise/Resources/Settings.bundle"
settings_plist="$settings_bundle/Root.plist"
/usr/libexec/PlistBuddy \
-c "Set :PreferenceSpecifiers:2:DefaultValue ${api_request}" "$settings_plist"
/usr/libexec/PlistBuddy \
-c "Set :PreferenceSpecifiers:8:DefaultValue ${branch}" "$settings_plist"
# 修改APP Display Name
display_name="jenkins.TEST"
info_plist="${PROJECT_PATH}/Enterprise/Enterprise/Resources/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $display_name" "$info_plist"
# 修改APP-Icon
app_icon="${PROJECT_PATH}/Enterprise/Enterprise/Resources/Assets.xcassets/"
test_icon="${PROJECT_PATH}/Enterprise/Enterprise/Resources/Tests/AppIcon.appiconset"
cp -f -R $test_icon $app_icon
# 网络请求报错弹窗
if $show_api_error_alert
then
api_file="${PROJECT_PATH}/YCAPIClient/APIClient.swift"
sed -i "" "85s/\/\//""/" "$api_file"
fi
# 设置配置标识,编译环境(根据需要自行填写 release |debug ) Jenkins
configuration="Jenkins"
# 工程名(根据项目自行填写)
APP_NAME="jenkins_demo"
# TARGET名称(根据项目自行填写)
TARGET_NAME="Enterprise"
# 日期
DATE=$(date +%Y%m%d-%H-%M-%S)
# 工程文件路径
ARCHIVE_NAME="${APP_NAME}-${DATE}.xcarchive"
# 要上传的ipa文件路径 ${username} 需要换成自己的用户名
ROOT_PATH="/Users/username/Desktop/jenkins"
ARCHIVE_PATH="${ROOT_PATH}/Archive/${ARCHIVE_NAME}"
IPA_PATH="${ROOT_PATH}/Export"
FILE_PATH="${IPA_PATH}/${APP_NAME}.ipa"
echo "\n++++++++ PATHs:"
echo "PROJECT_PATH: ${PROJECT_PATH}"
echo "ARCHIVE_PATH: ${ARCHIVE_PATH}"
echo "IPA_PATH: ${IPA_PATH}"
# 导包方式(这里需要根据需要手动配置:AdHoc/AppStore/Enterprise/Development)
EXPORT_METHOD="AdHoc"
EXPORT_METHOD_PLIST_PATH=${SETTING_PATH}/UKeAdHocExportOptions.plist
# 指ipa定输出文件夹
rm -rf "${ROOT_PATH}/Archive/"
rm -rf ${IPA_PATH}
mkdir -pv ${IPA_PATH}
# 进入工程源码根目录
cd "${PROJECT_PATH}/${TARGET_NAME}"
xcworkspace_name="${TARGET_NAME}.xcworkspace"
echo "\n"
echo "️️ =================clean================= ️️ "
xcodebuild clean -workspace ${xcworkspace_name} \
-scheme "${TARGET_NAME}" \
-configuration ${configuration} \
-UseModernBuildSystem=YES
echo "\n"
echo " *** 正在 构建项目 "
xcodebuild archive -workspace ${xcworkspace_name} \
-scheme ${TARGET_NAME} \
-configuration ${configuration} \
-archivePath ${ARCHIVE_PATH} \
-destination 'generic/platform=iOS' \
-quiet
# 检查是否构建成功
# xcarchive 实际是一个文件夹不是一个文件所以使用 -d 判断
if [ -d "$ARCHIVE_PATH" ] ; then
echo "✅ *** [项目构建成功] "
else
echo "❌ *** [项目构建失败] "
exit 1
fi
echo ' ***************** 正在 打包 ***************** '
echo ${CODE_SIGNING_IDENTITY}
xcodebuild -sdk iphoneos \
-exportArchive \
-archivePath ${ARCHIVE_PATH} \
-exportPath ${IPA_PATH} \
-exportOptionsPlist ${EXPORT_METHOD_PLIST_PATH} \
-allowProvisioningUpdates \
-allowProvisioningDeviceRegistration \
CODE_SIGN_IDENTITY="Apple Distribution: 生产证书的名字 Technology Co., Ltd."
if [ -e ${FILE_PATH} ]; then
echo "✅ *** .ipa文件已导出 ***"
echo $FILE_PATH
else
echo "❌ *** 创建.ipa文件失败 ***"
exit 1
fi
# exit 0
echo ' *** 打包完成 ***'
cd "${PROJECT_PATH}"
commit_sha1=`git rev-parse --short HEAD | awk '{print $1}'`
commit_log=`git log --pretty=format:“%s” $commit_sha1 -4`
updateDescription="${branch} | ${api_request} | ${commit_sha1} \nrecent_commits:\n"
update_desc=`echo $updateDescription`
echo " 上传蒲公英 ++++++++++++++upload+++++++++++++"
curl -F "file=@${FILE_PATH}" \
-F "uKey=蒲公英的key" \
-F "_api_key=蒲公英的key" \
-F "updateDescription=${update_desc}${commit_log}" \
http://upload.pgyer.com/apiv1/app/upload
echo "✅ *** 上传蒲公英完成 ***"
if $notify_wechat
then
echo "→ *** 通知企微群 ***"
noti_msg="打包完成\nBranch:${branch},\nCommit:${commit_sha1},\nDefaultAPI:${api_request}\nDownload:https://www.pgyer.com/XD2i"
content=$noti_msg
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=企微的key' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "text",
"text": {
"content": "'$content'",
"mentioned_list":["@all"]
}
}'
echo "✅ *** 通知企微群完成 ***"
fi
有的时候我们把终端关了,再去打开网址,发现报错,
再次启动:
java -jar /Users/maxiaoliao/Desktop/jenkins/soft/jenkins.war
如何让jenkins自启动呢
进入这个目录下
1).可以使用brew
安装jenkins-lts
会自动帮我们下载openjdk@11
$ brew install jenkins-lts
/Users/用户名/Library/LaunchAgents
看这个目录下是否有 homebrew.mxcl.jenkins-lts.plist
的文件
没有的话 看看这里 /usr/local/opt/jenkins-lts
Label
homebrew.mxcl.jenkins-lts
ProgramArguments
/usr/local/opt/openjdk@11/bin/java
-Dmail.smtp.starttls.enable=true
-jar
/Users/maxiaoliao/Desktop/jenkins/soft/jenkins.war
--httpListenAddress=127.0.0.1
--httpPort=8080
RunAtLoad
/usr/local/opt/openjdk@11/bin/java :java替身 路径
/Users/maxiaoliao/opt/jenkins/soft/jenkins.war :2.263.4jenkins.war路径
把.plist
文件放在/Users/用户名/Library/LaunchAgents
下
终端执行一下
检查plist语法是否正确
$ plutil ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
修改文件权限
$ chmod 644 ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
添加自启动项
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist
启动自启动项
$ launchctl start homebrew.mxcl.jenkins-lts
查看当前所有自启动项
$ launchctl list
参考博客:
https://blog.csdn.net/qq_38082146/article/details/118334569
https://www.jianshu.com/p/eee8a7de179c