Jenkins持續(xù)集成環(huán)境搭建-Mac

一、安裝方式

(一)、homebrew安裝Jenkins

1、安裝homebrew
https://brew.sh
卸載:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

安裝:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、安裝jenkins
install the latest release version
brew install jenkins
或者
install the LTS version
brew install jenkins-lts

安裝過(guò)程如下圖:
截屏2021-03-26 上午10.03.17.png

安裝路徑:/usr/local/Cellar/jenkins-lts/2.150.1

更新:brew upgrade jenkins-lts
截屏2021-03-26 上午10.04.07.png

brew cleanup:清楚brew的一些緩存
截屏2021-03-26 上午10.04.45.png

3、啟動(dòng)
后臺(tái)服務(wù)模式:brew services start jenkins-lts
無(wú)需后臺(tái)服務(wù)模式:jenkins-lts

啟動(dòng)過(guò)程如下圖:
截屏2021-03-26 上午10.05.15.png

4、停止

服務(wù)停止:brew services stop jenkins-lts
截屏2021-03-26 上午10.05.37.png

重新啟動(dòng)jenkins:brew services restart jenkins-lts

Note:如果瀏覽器中輸入http://localhost:8080無(wú)反應(yīng),可嘗試重啟jenkins服務(wù)。

可用插件列表為空的解決方案

截屏2021-03-26 上午10.06.26.png

原始:http://updates.jenkins-ci.org/update-center.json
http://mirror.esuni.jp/jenkins/updates/update-center.json

(二)、WAR file

1、官網(wǎng)下載具體Jenkins WAR file至某一路徑下
2、打開(kāi)終端
3、執(zhí)行 java -jar jenkisn.war,啟動(dòng)Jenkins服務(wù),后續(xù)
4、瀏覽器:http://localhost:8080 ,即可看到Jenkins頁(yè)面

note:

  • You can change the port by specifying the --httpPort option when you run the java -jar jenkins.war command. For example, to make Jenkins accessible through port 9090, then run Jenkins using the command:

java -jar jenkins.war --httpPort=9090

5、之后用mac自帶的automator,選擇運(yùn)行腳本,腳本內(nèi)容為:java -jar jenkins.war,保存為應(yīng)用程序,再添加至登錄項(xiàng),至此Jenkins自動(dòng)啟動(dòng)完成.

(三)、tomcat

tomcat與jenkins的安裝

1.homebrew 安裝tomcat:brew install tomcat(tomcat路徑: /usr/local/Cellar/tomcat)
2.執(zhí)行startup.sh,啟動(dòng)tomcat
3.在瀏覽器中輸入localhost:8080,如果能看到tomcat首頁(yè),安裝就成功了
4.官網(wǎng)下載https://jenkins.io/index.html jenkins,將war包拷貝到/Library/tomcat/webapps下
5.執(zhí)行shutdown.sh關(guān)閉tomcat,并再次啟動(dòng)
6.在瀏覽器中輸入http://localhost:8080/jenkins/,如果能看到j(luò)enkins配置頁(yè)面,安裝就成功了

二、啟動(dòng)
1、http://localhost:8080,如下圖:

截屏2021-03-26 下午3.22.28.png

按照提示,填寫(xiě)password,

2、Continue,選擇“Install suggested plugins”,安裝即可(可忽略,可以在系統(tǒng)管理->管理插件中再行安裝;(若源碼管理使用git,則必須安裝git plugin,git client plugin))


截屏2021-03-26 下午3.23.01.png
截屏2021-03-26 下午3.23.47.png

jenkins插件下載庫(kù):http://updates.jenkins-ci.org/download/plugins/

3、在最初啟動(dòng)時(shí),會(huì)要求設(shè)置Jenkins的用戶名和密碼,為Jenkins添加訪問(wèn)權(quán)限。

4、進(jìn)行系統(tǒng)設(shè)置,目前只配置了這幾個(gè)


截屏2021-03-26 下午3.24.21.png
截屏2021-03-26 下午3.25.04.png
截屏2021-03-26 下午3.25.18.png
截屏2021-03-26 下午3.25.33.png

4、創(chuàng)建一個(gè)自由風(fēng)格的軟件項(xiàng)目

參考:https://blog.csdn.net/taishanduba/article/details/61423121

截屏2021-03-26 下午3.26.00.png

設(shè)置Source Code Management(目前使用git)
添加相關(guān)shell,下面主要是打包(adhoc)

echo "workspace $1"
echo "jenkins_home $2"
workspace=$1
jenkins_home=$2

# 以下是用xcodebuild進(jìn)行打包
# 開(kāi)始build
echo "[build start ...]"
configurationBuildDir="$workspace/build"
echo "[configurationBuildDir :$configurationBuildDir]"

configuration="WiseTVAdHoc"
cd $workspace/WiseTV4.0
xcodebuild clean -configuration ${configuration}
clean_code=$?
if [[ "$clean_code" != "0" ]]; then
  echo "xcodebuild clean error!"
  exit 1
fi
cd ..
cd ..

workspaceName="$workspace/WiseTV4.0/WiseTV.xcworkspace"
scheme="WiseTVAdHoc"
archivePath="$configurationBuildDir/WiseTVAdHoc.xcarchive"

echo "xcodebuild archive -workspace $workspaceName -scheme $scheme -configuration $configuration -archivePath $archivePath CONFIGURATION_BUILD_DIR=$configurationBuildDir CODE_SIGN_IDENTITY=$codeSignIdentity PROVISIONING_PROFILE=$adHocProvisioningProfile"

xcodebuild -workspace ${workspaceName} -scheme ${scheme} -configuration ${configuration} archive -archivePath ${archivePath}

archive_code=$?
if [[ "$archive_code" != "0" ]]; then
  echo "xcodebuild archive error!"
  exit 1
fi

echo "[build success!]"

# 開(kāi)始打包ipa
echo "[package ipa ...]"
exportOptionsPlist="$jenkins_home/workspace/iphoneAdHoc/WisetvExportOptions.plist"
exportPath=$configurationBuildDir

echo "xcodebuild -exportArchive -archivePath $archivePath -exportOptionsPlist $exportOptionsPlist -exportPath $exportPath"

xcodebuild -exportArchive -archivePath ${archivePath} -exportOptionsPlist ${exportOptionsPlist} -exportPath ${exportPath}

export_code=$?
if [[ "$export_code" != "0" ]]; then
  echo "xcodebuild exportArchive error!"
  exit 1
fi

echo "[package ipa success!]"

# echo "[clear cache ...]"
# rm -rf "$configurationBuildDir"
# echo "[clear cache success!]"

5、publish 包

1、可以使用fir plugin 上傳ipa包,具體請(qǐng)看http://blog.fir.im/jenkins/

2、使用fir命令行publish包,具體請(qǐng)查看https://github.com/FIRHQ/fir-cli
如果log輸出:fir command not found,可按照
https://blog.csdn.net/pengyuan_D/article/details/51861098 修改

6、構(gòu)建結(jié)果郵件通知
https://www.cnblogs.com/imyalost/p/8781759.html

構(gòu)建過(guò)程中問(wèn)題總結(jié):

1、xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

這種情況是xcodebuild的路徑不正確


截屏2021-03-26 下午3.40.01.png

將路徑切換到xcode的目錄下:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
然后執(zhí)行xcodebuild -showsdks查看是否正常使用
2、xcodebuild 命令詳解
http://www.itdecent.cn/p/770d5df137bf
3、獲取fir api token
https://www.betaqr.com/apps/apitoken
當(dāng)前:737b8fca97cc6e094951449884f263d5

三、fir.im-cli指令上傳ipa包

fir cli https://github.com/FIRHQ/fir-cli/tree/master/doc

安裝:
$ ruby -v # > 2.6.1

$ gem install fir-cli
登錄:
fir login token
fir me
更新:
fir upgrade
發(fā)布:
fir publish APP_FILE_PATH

四、在jenkins中使用fir-plugin

安裝fir-plugin,或者下載此插件,然后在jenkins插件管理中上傳使用
添加Post-build Actions,選擇upload to fir.im.
填寫(xiě)token,可以使用鏈接查看https://www.betaqr.com/apps/apitoken,因?yàn)閒ir的域名的更改,文檔中的鏈接不支持查看。填寫(xiě)ipa包所在路徑,因?yàn)闀?huì)自動(dòng)上傳路徑下所有的ipa包,所以這里做了一個(gè)操作,將要上傳的ipa包拷貝至了一個(gè)特定的路徑(mv $WORKSPACE/build/Apps/WiseTVAdHoc.ipa /Users/dongranran/Public/ipa/),如下圖

截屏2021-03-26 下午3.43.10.png

Jenkins官網(wǎng):https://jenkins.io
Jenkins Pipeline總體介紹 https://blog.csdn.net/diantun00/article/details/81075007

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容