0.jenkins的原理

将代码托管到服务器,jenkins执行build之前需要去服务器(git or svn)拉取最新的代码到本地,参考目录为 /Users/admin/.jenkins/workspace

1.安装java jdk

由于Jenkins目前只支持Java8-11,所以不能安装Java12

可以到官网下载https://www.oracle.com/technetwork/java/javase/downloads/index.html

也可以使用brew 安装

brew cask install java11

2.安装Jenkins

brew install jenkins 

推荐使用brew安装Jenkins,如果使用官网的pkg包安装,会出现各种蛋疼的权限问题

⚠️:安装成功后,需要记录admin的初始密码

3.执行war包

java -jar /usr/local/Cellar/jenkins/版本号/libexec/jenkins.war --httpPort=8080

当命令行中提示“Jenkins is fully up and running”即表示执行成功,可以进行下一步的操作

安装之后先不要打开localhost:8080

4.open /Library/LaunchDaemons

open /Library/LaunchDaemons

在里面新建一个文件org.jenkins-ci.plist,其的内容为

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>StandardOutPath</key>
    <string>/var/log/jenkins/jenkins.log</string>
    <key>StandardErrorPath</key>
    <string>/var/log/jenkins/jenkins.log</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>JENKINS_HOME</key>
      <string>/Users/admin/Documents/Jenkins/Home</string>
    </dict>
    <key>GroupName</key>
    <string>daemon</string>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.jenkins-ci</string>
    <key>ProgramArguments</key>
    <array>
      <string>/bin/bash</string>
      <string>/Library/Application Support/Jenkins/jenkins-runner.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>jenkins</string>
    <key>SessionCreate</key>
    <true/>
  </dict>
</plist>

5.启动Jenkins 

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

这里可能会遇到Path had bad ownership/permissions权限问题,执行

sudo chown root:wheel /Library/LaunchDaemons/org.jenkins-ci.plist

然后重复执行上边 启动jenkins 的命令

6.网页中打开localhost:8080,就可以正常操作了,附上一个jenkins的打包脚本

xcodebuild -archivePath "/Users/admin/Desktop/未命名文件夹/JenkinsApp/build/archive/JenkinsApp.xcarchive"  -sdk iphoneos -scheme "JenkinsApp" -configuration "Release" archive

xcodebuild -exportArchive -archivePath "/Users/admin/Desktop/未命名文件夹/JenkinsApp/build/archive/JenkinsApp.xcarchive" -exportPath "/Users/admin/Desktop/未命名文件夹/JenkinsApp/build/ipa" -exportOptionsPlist '/Users/admin/Desktop/未命名文件夹/JenkinsApp/ExportOptions.plist' -allowProvisioningUpdates

参考链接:

mac下Jenkins 主目录导致的权限问题(参考jenkins环境配置) https://www.jianshu.com/p/dc6f3fea7aa9

Jenkins在MAC上搭建CI(持续化集成)终结版(参考Jenkins的使用) https://www.jianshu.com/p/d76c9fd8dac5

修改插件的source地址https://blog.csdn.net/you227/article/details/81076032

fastlane+jenkins https://www.jianshu.com/p/3b4a131653e0

07-30 19:43