前言
在Fastfile文件中镀钓,常常需要執(zhí)行一些其他的腳本及命令取逾,同時(shí)還要打印日志
一诱鞠、在Fastfile中執(zhí)行Shell命令
參考:
sh("命令")
: 最原始的方式付燥,返回打印的日志
sh("shell路徑")
: 最原始的方式舔糖,返回打印的日志
Helper.backticks("命令")
:執(zhí)行耗時(shí)比較短的命令,返回打印的日志
FastlaneCore::CommandExecutor.execute(command: "命令")
:建議的方式
system("命令")
: 執(zhí)行完后返回true/false
exec("命令")
: 執(zhí)行完后會(huì)強(qiáng)制結(jié)束街图,不再往下執(zhí)行
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")
#以下因?yàn)閑xec會(huì)強(qiáng)制結(jié)束不會(huì)被執(zhí)行
UI.message "result5:#{result5}"
UI.message "end=======end"
end
end
hello.sh的腳本內(nèi)容:
#! /bin/bash
echo "I am Hello world"
pwd
結(jié)果如下:
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/fastlane16: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/fastlane16:41:28: $ pwd
16:41:28: ? /Users/tony/fastlane_workspace/OwnActionPlugin/fastlane
16:41:28: result2:/Users/tony/fastlane_workspace/OwnActionPlugin/fastlane16: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
:接收從多個(gè)選擇中選擇一個(gè)選項(xiàng)
更多參考: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中執(zhí)行打印日志
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: --------------------------------