Fastlane CLI传入参数被截断:PR标题参数传递异常
问题
我尝试把Pull Request(PR)标题作为参数传给Fastlane的distribute lane,执行命令:
fastlane android distribute release_notes:$PR_TITLE
从日志里能看到命令携带了完整标题:
[16:37:52]: $ bundle exec fastlane android distribute release_notes:ref: copy the services module inside app module
但在lane代码里打印传入的参数时,发现参数被截断,只输出release_notes ref:;而且如果标题里有换行符,也会导致参数异常截断。对应的lane代码如下:
desc "distribute new build for testers, set internal to true to pass it for internal testrs" lane :distribute do |options| print "\n" print "release_notes" print options[:release_notes]
解决办法
问题根源是shell会把PR标题里的空格、冒号这类字符当作参数分隔符,导致Fastlane只能接收到第一个分隔符前的内容。给两个靠谱的解决方式:
方式1:用引号包裹参数
执行命令时,把$PR_TITLE用双引号括起来,让shell把整个标题当成一个完整参数传递:fastlane android distribute release_notes:"$PR_TITLE"不管标题里有空格、冒号还是换行符,都能完整传给Fastlane。
方式2:通过环境变量传递(更适配特殊字符场景)
如果PR标题里包含引号这类更特殊的字符,用环境变量更稳妥:- 先设置环境变量:
export PR_TITLE="$PR_TITLE" - 修改lane代码,直接读取环境变量:
desc "distribute new build for testers, set internal to true to pass it for internal testrs" lane :distribute do |options| print "\n" print "release_notes: " print ENV['PR_TITLE'] end
执行命令时不用传
release_notes参数,直接运行:fastlane android distribute- 先设置环境变量:
内容的提问来源于stack exchange,提问作者David Ibrahim
相关产品推荐
相关产品推荐

