fastlane 执行Shell及打印日志消息

前言

在Fastfile文件中,常常需要执行一些其他的脚本及命令,同时还要打印日志

一、在Fastfile中执行Shell命令

参考:

sh("命令") : 最原始的方式,返回打印的日志
sh("shell路径") : 最原始的方式,返回打印的日志
Helper.backticks("命令"):执行耗时比较短的命令,返回打印的日志
FastlaneCore::CommandExecutor.execute(command: "命令"):建议的方式
system("命令"): 执行完后返回true/false
exec("命令"): 执行完后会强制结束,不再往下执行
Fastfile的demo如下:

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
     result0 = sh( "./../hello.sh")
     UI.message "result0:#{result0}"
     result1 = sh("pwd")
     UI.message "result1:#{result1}"
     result2 = Helper.backticks("pwd")
     UI.message "result2:#{result2}"
     result3 = FastlaneCore::CommandExecutor.execute(command: "pwd")
     UI.message "result3:#{result3}"
     result4 = system("pwd")
     UI.message "result4:#{result4}"
     result5 = exec("pwd")
     #以下因为exec会强制结束不会被执行
     UI.message "result5:#{result5}"
     UI.message "end=======end"
  
  end
end

hello.sh的脚本内容:

#! /bin/bash
echo "I am Hello world"
pwd

结果如下:
16:41:28: ------------------------------
16:41:28: --- Step: default_platform ---
16:41:28: ------------------------------
16:41:28: Driving the lane 'ios custom_lane' 🚀
16:41:28: ---------------------------
16:41:28: --- Step: ./../hello.sh ---
16:41:28: ---------------------------
16:41:28: $ ./../hello.sh
16:41:28: ▸ I am Hello world
16:41:28: ▸ /Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
16:41:28: result0:I am Hello world
/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane

16:41:28: --- Step: pwd ---
16:41:28: -----------------
16:41:28: $ pwd
16:41:28: ▸ /Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
16:41:28: result1:/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane

16:41:28: $ pwd
16:41:28: ▸ /Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
16:41:28: result2:/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane

16:41:28: $ pwd
16:41:28: result3:/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
16:41:28: result4:true
/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane

1.2:

UI.input: 接受输入的文本
UI.password:接收输入的密码
UI.confirm:接收y/n的选择
UI.select:接收从多个选择中选择一个选项
更多参考:fastlane actions 交互
Fastfile的demo如下:

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
    name = UI.input("What's your name? ")
    pwd = UI.password("Your password please: ")
    confirm = UI.confirm("Are you '#{name}'?")
    UI.message "name:#{name}  pwd:#{pwd} confirm:#{confirm}"
  end
end

16:15:09: --- Step: default_platform ---
16:15:09: ------------------------------
16:15:09: Driving the lane 'ios custom_lane' 🚀
16:15:09: What's your name? jobs
[16:15:17]: Your password please: ***
[16:15:19]: Are you 'jobs'? (y/n)
y
[16:15:20]: name:jobs pwd:123 confirm:true

二、在Fastfile中执行打印日志
platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
     puts "hello---puts----111111"
     p "hello---p----2222222222"
     UI.message "hello---message----3333333"
     UI.important "hello---important----44444444"
     UI.error "hello---error----5555555"
     UI.success "hello---success----66666666"
     UI.header "hello---header----777777"
  end
end

17:02:51: --- Step: default_platform ---
17:02:51: ------------------------------
17:02:51: Driving the lane 'ios custom_lane' 🚀
17:02:51: hello---puts----111111
"hello---p----2222222222"
17:02:51: hello---message----3333333
17:02:51: hello---important----44444444
17:02:51: hello---error----5555555
17:02:51: hello---success----66666666
17:02:51: --------------------------------
17:02:51: --- hello---header----777777 ---
17:02:51: --------------------------------

打印日志效果
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • fastlane运行所需要的环境: OS X 10.9以上 Ruby 2.0 以上 Xcode 拥有一个开发者账号...
    阿姣_0405阅读 3,043评论 0 4
  • 前言 在终端中执行fastlane lane_name之后,fastlane会去执行Fastfile中定义的同名l...
    wangzzzzz阅读 1,831评论 6 8
  • 题目169. Majority Element Given an array of size n, find th...
    evil_ice阅读 319评论 0 0
  • 每日复盘 Objective 你对今天学的记得什么? 书到用时方恨少。 Reflective 一句话形容今天的情绪...
    露易司阅读 154评论 0 0
  • 反射弧超级长的我,现在才来感慨2018~ 没有跨年,也没有和亲爱的们出去嗨,说是准备期末考试,但想想还是自己的原因...
    小米111阅读 299评论 0 0