持续集成 使用 Jenkins 构建由 carthage 管理 framework 的 iOS 工程

nick · 发布于 2017年09月18日 · 最后由 yoyoqiekenao 回复于 2017年09月26日 · 596 次阅读
本帖已被设为精华帖!
  • 问题: carthage每次都需要去github拉去代码并构建,大大增加了构建的时间。
  • 思考: 作为一个framework管理工具,肯定会支持缓存构建,所以去github上查看官方文档。
  • 解决办法:
    在官方文档中找到如下一段说明,即使用--cache-builds即表示使用缓存进行构建。

    Caching builds

    By default Carthage will rebuild a dependency regardless of whether it's the same resolved version as before. Passing the --cache-builds will cause carthage to avoid rebuilding a dependency if it can. See information on version files for details on how carthage performs this caching.

  • 执行:
    修改Jenkins脚本,将命令carthage update --platform iOS修改为carthage update --platform iOS --cache-builds,然后很开心的在Jenkins job上点了构建。

    carthage update --platform iOS --cache-builds
    *** Fetching Charts
    *** Checking out Charts at "v3.0.2"
    *** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.JEKNY6.log
    *** No cache found for Charts, building with all downstream dependencies
    *** Building scheme "Charts" in Charts.xcodeproj

  • 但没找到cache,怀疑需要第二次build才可以。但事实是第二次依然提示No cache found。肯定是哪里不对,回过头来再次查看官方文档,发现如下一段介绍:

    If you're building for iOS, tvOS, or watchOS
    ...
    6.Add the paths to the copied frameworks to the “Output Files”, e.g.:
    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Result.framework
    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveSwift.framework
    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveCocoa.framework
    With output files specified alongside the input files, Xcode only needs to run the script when the input files have changed or the output files are missing. This means dirty builds will be faster when you haven't rebuilt frameworks with Carthage.

  • 然后对照我们的工程检查,发现并没有配置这个Output Files,原因应该就在这里了。随即找开发添加,并提交代码,触发构建。
    本以为这次可以命中cache,但得到无效cache的提示:

    carthage update --platform iOS --cache-builds
    *** Fetching Charts
    *** Checking out Charts at "v3.0.2"
    *** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.KZDaMB.log
    *** Invalid cache found for Charts, rebuilding with all downstream dependencies
    *** Building scheme "Charts" in Charts.xcodeproj

  • 这个就比较郁闷了,按照官方文档所有的配置都没有问题,参数也没有问题,而且在本地是可以命中cache的:

    carthage update --platform iOS --cache-builds
    *** Fetching Charts
    *** Checking out Charts at "v3.0.2"
    *** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.gxGJC9.log
    *** Valid cache found for Charts, skipping build

  • 而且开发提交代码后,在我的电脑上和开发的电脑上都可以命中cache,偏偏只有Jenkins无法命中cache。
    这个时候已经没有其他可能,不会是配置或者参数的问题了,那么来查看一下xcodebuild的日志吧。
    发现构建生成的Charts.framework所有的路径中有8.1_8B62,而这个正式Jenkins服务器上xcode的版本。所以猜测carthage的cache和xcode的版本有关。

    Signing Identity: "-"

    /usr/bin/codesign --force --sign - --timestamp=none /Users/nick/Library/Caches/org.carthage.CarthageKit/DerivedData/8.1_8B62/Charts/v3.0.2/Build/Products/Release-iphonesimulator/Charts.framework

    ** BUILD SUCCEEDED **

  • 随即升级了xcode版本到8.3.3,然后再次构建,成功命中缓存。

    carthage update --platform iOS --cache-builds
    *** Fetching Charts
    *** Checking out Charts at "v3.0.2"
    *** xcodebuild output can be found in /var/folders/64/xp952xv54zdb577b33ngw2rw0000gn/T/carthage-xcodebuild.8aIUyY.log
    *** Valid cache found for Charts, skipping build


关于Carthage

Carthage is intended to be the simplest way to add frameworks to your Cocoa application.

The basic workflow looks something like this:

  1. Create a Cartfile that lists the frameworks you’d like to use in your project.
  2. Run Carthage, which fetches and builds each framework you’ve listed.
  3. Drag the built .framework binaries into your application’s Xcode project.

Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup. Carthage does not automatically modify your project files or your build settings.

共收到 2 条回复
104 seveniruby 将本帖设为了精华贴 09月20日 11:11
4365

用--cache-builds的确快很多,目前有些repo没法cache,还需要重新拉一次

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册