关于Mac上部署Jenkins的一些个人习惯

原创文章转载请注明出处

Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:
1、持续的软件版本发布/测试项目。
2、监控外部调用执行的工作。

《关于Mac上部署Jenkins的一些个人习惯》 Paste_Image.png
《关于Mac上部署Jenkins的一些个人习惯》 Paste_Image.png

去年因为要做持续集成,在公司的苹果主机上部署了Jenkins,网上的安装教程已经非常多了,这里记录一些个人的配置习惯。

  1. 因为要打包iOS App,所以必须部署在macOS上,性能当然越高越好。我在某宝买了一台黑苹果,主机价格不到4K,志强处理器+8G内存+250G固态硬盘+1T机械硬盘,系统做得很好,运行稳定,美中不足就是升级系统大版本需要把硬盘寄回给卖家。涉及到公司机密的文件保护,所以我把所有的资源都放在机械硬盘中,固态硬盘仅保留macOS系统和软件,如果有钱还是建议上一台MacPro。
  2. 不要用pkg文件安装Jenkins,因为这样会生成一个共享用户jenkins,而这个用户的权限和系统登录用户的权限不同,在编译iOS应用的时候会有证书校验和签名的问题,所以请下载war包,放到Java容器中执行,比如Tomcat。我在系统启动的时候自启动了Tomcat,所以开机以后Jenkins会自动启动。
  3. 前面说了数据都放在机械硬盘中,所以要修改Jenkins的工作目录。打开Tomcat的bin目录,编辑catalina.sh文件。找到以下代码:
# OS specific support.  $var _must_ be set to either true or false.

在这句话上面添加下面这句话,在引号中填入你的路径。

export JENKINS_HOME=""

这个操作在拷贝Jenkins的war包之前就可以做了。

  1. 现在没有账号权限的困扰了,但是xcodebuild -exportArchive的时候会报错。
xcodebuild[62682:464728] [MT] IDEDistribution: Step failed: <IDEDistributionThinningStep: 0x7ff1a42d23f0>:
 Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo=0x7ff1a72ddd80 {NSLocalizedDescription=No applicable devices found.}error: exportArchive: No applicable devices found.Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo=0x7ff1a72ddd80 {NSLocalizedDescription=No applicable devices found.}
** EXPORT FAILED **

什么鬼,你会看到这个莫名其妙的错误。Google会告诉你这是因为RVM中安装的ruby版本和Xcode要求的版本不一致。抄一个xcodebuild-safe.sh的脚本,export的时候用这个脚本处理,代码在文章末尾,拿走不谢,反正也不是我写的,我只是代码搬运工。

xcodebuild-safe -exportArchive ..........
  1. 打包这种事,能用脚本解决的问题就不要用额外的插件了,那些Android Studio/Xcode的插件,我都没有安装。

《关于Mac上部署Jenkins的一些个人习惯》 Paste_Image.png

命令行这东西是最方便的,可定制化程度高,不是吗?Bash Shell和Python已经足够应付所有的打包工作了。

附送xcodebuild-safe.sh

#!/bin/bash --login

# Cf. http://stackoverflow.com/questions/33041109
#
# Xcode 7 (incl. 7.0.1) seems to have a dependency on the system ruby.
# xcodebuild is screwed up by using rvm to map to another non-system
# ruby†. This script is a fix that allows you call xcodebuild in a
# "safe" rvm environment, but will not (AFAIK) affect the "external"
# rvm setting.
#
# The script is a drop in replacement for your xcodebuild call.
#
#   xcodebuild arg1 ... argn
#
# would become
#
#   path/to/xcbuild-safe.sh arg1 ... argn
#
# -----
# † Because, you know, that *never* happens when you are building
# Xcode projects, say with abstruse tools like Rake or CocoaPods.

# This allows you to use rvm in a script. Otherwise you get a BS
# error along the lines of "cannot use rvm as function". Jeez.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

# Cause rvm to use system ruby. AFAIK, this is effective only for
# the scope of this script.
rvm use system

unset RUBYLIB
unset RUBYOPT
unset BUNDLE_BIN_PATH
unset _ORIGINAL_GEM_PATH
unset BUNDLE_GEMFILE

set -x          # echoes commands
xcodebuild "$@" # calls xcodebuild with all the arguments passed to th

我是咕咕鸡,一个还在不停学习的全栈工程师。
热爱生活,喜欢跑步,家庭是我不断向前进步的动力。

    原文作者:咕咕鷄
    原文地址: https://www.jianshu.com/p/315fcf2c37b6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞