背景:iOS 自动化打包 Jenkins + fastlane + 蒲公英上传
问题:在构建日志中提示 pod install 报错问题
`
15:13:28 [!] The version of CocoaPods used to generate the lockfile (1.13.0) is higher than the version of the current executable (1.10.1). Incompatibility issues may arise.
15:13:28 Analyzing dependencies
15:13:28 /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface/error_report.rb:34:in `force_encoding': can't modify frozen String (FrozenError)
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface/error_report.rb:34:in `report'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:66:in `report_error'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in `handle_exception'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in `rescue in run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in `run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/pod:25:in `load'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/pod:25:in `<main>'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `eval'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `<main>'
15:13:28 /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:228:in `initialize_from_file': [Xcodeproj] Unknown object version (60). (RuntimeError)
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:113:in `open'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1186:in `block (2 levels) in inspect_targets_to_integrate'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1185:in `each'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1185:in `block in inspect_targets_to_integrate'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:1180:in `inspect_targets_to_integrate'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:106:in `analyze'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:414:in `analyze'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:238:in `resolve_dependencies'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:160:in `install!'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command/install.rb:52:in `run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
15:13:28 from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/pod:25:in `load'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/pod:25:in `<main>'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `eval'
15:13:28 from /Users/xxx/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `<main>'
15:13:28 Build step 'Execute shell' marked build as failure
思考问题:
1.ruby 环境 和 pod 环境 都不对。我本地 ruby 环境 是 ruby 3.0.0 pod环境 是 1.13.0
然后去 jenkins 全局环境配置修改了 ruby版本 ,结果还是报错(同样的错)。迫不得已 google 一顿找资料。找到一个合适方案,安装 RVM 插件,来管理构建时使用那个版本的 ruby。结果安装的时候发现个根本没有这个插件,查了一下插件的历史,才知道,该插件早已在 2022年 1月份 全部下架了。
玛德!玛德!玛德!
然后我把 Jenkins 插件全部升级到最新。当然问题还是存在。
最后再次检查错误:注意到:“ Build step 'Execute shell' marked build as failure”
于是恶补了一下 shell 的知识资料;
一般默认情况下,Jenkins采取/bin/sh -xe这种方式-x将打印每一个命令;另一个选项-e,当任何命令以非零值(当任何命令失败时)退出代码时,这会导致shell立即停止运行脚本,而#!/bin/bash是指此脚本使用/bin/bash来解释执行
注释1:#!是一个特殊的表示符,后面表示解释此脚本的shell路径 注释2:bash只是shell的一种,还有很多其它shell,如:sh,csh。。等等 注释3:#!/bin/bash只能放在第一行,如果后面还有#!,那么只能看成是注释
最终方案,在构建过程 shell 增加: #!/bin/bash
重新运行 打包成功。 真TM神坑。