美文网首页
在Xcode Server中使用fastlane和CocoaPo

在Xcode Server中使用fastlane和CocoaPo

作者: Jagtu | 来源:发表于2019-07-07 12:34 被阅读0次

创建Xcode Bots的时候我们就知道了,可以添加prebuild scripts 和 postbuild scripts 两个脚本。

实际上,我们首先需要了解到一点,Xcode Server在运行的使用是使用了一个独立的用户来运行程序的,这个用户就是_xcsbuildd。

1、使用CocoaPods

CocoaPods is a great dependency manager for Xcode projects. It allows you to integrate other people’s (or your own) code in your project easily.

  1. create a Podfile in your project,Then we just need to actually have CocoaPods install the dependencies and start using the workspace instead of the project.
  2. create Bot and see if it can rebuild our project with the new shiny Pod in it!

2、Prebuild script: run CocoaPods

现在编辑Bot,选择添加一个prebuild Script trigger

cd [Project1Name] pod install

你可能会得到一个错误

...: line 3: pod: command not found

这是因为build是使用的用户_xcsbuildd找不到CocoaPods,你应该是安装在了/usr/local/bin (which is not included in the build user’s PATH variable)

四个解决办法:

1)指定工具的完整路径:/usr/local/bin/pod install

2)通过在脚本开头添加行export path=“/usr/local/bin:$path”,手动添加额外的搜索路径。

3)通过运行以下命令创建符号链接:

sudo ln -s /usr/local/bin/pod /usr/bin/pod

只需一次,这将使pod在/usr/bin中可用,但实际上指向/usr/local/bin中的可执行文件。

I’ve heard that the symbolic link solution doesn’t seem to work with El Cap anymore

3、登录_xcsbuildd用户

以“xcsbuild”用户身份登录,才可以配置Private CocoaPod所对应的使用仓库的SSH Keys,从而使pod install 能够成功。避免出现以下类似的错误

Cloning into 'XXXPodspecRepository'... Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

可以使用su命令来切换用户

$ sudo su - _xcsbuildd su: /bin/false: No such file or directory

如上报错的话,那是因为_xcsbuildd因没有设置shell(一种实现交互式登录会话的方法),那我们就设置它,使用命令dscl

$ sudo dscl localhost -change /Local/Default/Users/_xcsbuildd UserShell /bin/false /bin/bash

“Hey directory service, on this computer, please change the shell of the user _xcsbuildd from /bin/false to /bin/bash.”

sudo su - _xcsbuildd honza-dvorskys-mbpr-14:~ _xcsbuildd whoami _xcsbuildd pwd ~ /var/_xcsbuildd

完美. 我们现在登录了 _xcsbuildd 确定在主目录是 /var/_xcsbuildd!

Adding SSH keys

要么拷贝你现有的.ssh到这个新用户

sudo -s mkdir /var/_xcsbuildd/.ssh cp /Users/honzadvorsky/.ssh/id_rsa /var/_xcsbuildd/.ssh/ cp /Users/honzadvorsky/.ssh/id_rsa.pub /var/_xcsbuildd/.ssh/ cp /Users/honzadvorsky/.ssh/known_hosts /var/_xcsbuildd/.ssh/ chown _xcsbuildd:_xcs /var/_xcsbuildd/.ssh/id_rsa chown _xcsbuildd:_xcs /var/_xcsbuildd/.ssh/id_rsa.pub chown _xcsbuildd:_xcs /var/_xcsbuildd/.ssh/known_hosts $ exit

要么创建新的SSH Keys

whoami # make sure we're _xcsbuildd cd ~/.ssh #make sure .ssh exist. mkdir .ssh # or create .ssh ssh-keygen -t rsa -C "your@email.com" ... Your identification has been saved in /var/_xcsbuildd/.ssh/id_rsa. Your public key has been saved in /var/_xcsbuildd/.ssh/id_rsa.pub. ... $ exit # switch back to your user ... sudo cat /var/_xcsbuildd/.ssh/id_rsa.pub | pbcopy #pbcopy is another preinstalled tool, which pipes its input into the clipboard. Super handy! ... Now we just need to add our new public key to e.g. GitHub in Settings -> SSK keys -> Add SSH key. ...

[图片上传失败...(image-5e571a-1562474033818)]

Confirming known_hosts

我们还需要配置known_hosts来信任你的私有仓库host,否则你可能会获得如下的错误

Cloning spec repo xxxFromework from git@github.com:xxxx/XXX.git [!] Unable to add a source with url git@github.com:xxxx/XXX.git named xxx.

那么

sudo su - _xcsbuildd ssh -T git@github.com # substitute with your podspec git repo's server The authenticity of host 'github.com (192.30.252.131)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts. Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. #Cool! Let’s run it again just to confirm… ssh -T git@github.com Hi czechboy0! You've successfully authenticated, but GitHub does not provide shell access.

Perfect!

Postbuild script: run fastlane

FastLane是一个运行各种操作的强大工具,您可以向您的fastfile添加任何您想要的操作!(比如上传到crashlytics beta/hockeyapp/testfirght等)

假设您已经安装了fastlane,同样,如果您使用的是非系统Ruby,那么首先需要解决 command not found 的问题,更pod是医一样的。

那么很简单的一个脚本

cd [YourProjectName] fastlane postbuild

[图片上传失败...(image-680044-1562474033817)]

Environment variables in scripts

查看Xcode server提供的一些环境变量 Xcode Server Environment Variable Reference

你也可以在脚本中使用 set 来输出。

相关文章

网友评论

      本文标题:在Xcode Server中使用fastlane和CocoaPo

      本文链接:https://www.haomeiwen.com/subject/xjsbhctx.html