Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Variable in Fastlane Script

Tags:

ruby

fastlane

Sorry for such a newbie question, but I'm very confused on how to write a Fastlane script outside of using the supplied methods.

What I'm looking to do is create a variable called message, that can be passed to the after_all function, so when I post to Slack, each lane can have it's own custom message:

put message # is this how to set a variable?
lane :alpha do
    # This is what I'd like to do
    message = "[Google Play] Alpha Channel Deployed"
end

after_all |lane, options| do
    slack(message: message)
end

Can anyone point me in the right direction? I'm so utterly lost on how to create and pass variables that don't come from the command line in a Fastfile script

like image 746
EHorodyski Avatar asked Feb 09 '17 16:02

EHorodyski


People also ask

What is Fastfile?

The Fastfile stores the automation configuration that can be run with fastlane. The Fastfile has to be inside your ./fastlane directory. The Fastfile is used to configure fastlane. Open it in your favourite text editor, using Ruby syntax highlighting.

How do you define a global variable in Ruby?

Global Variable has global scope and accessible from anywhere in the program. Assigning to global variables from any point in the program has global implications. Global variable are always prefixed with a dollar sign ($).

What are Fastlane lanes?

noun. Also called express lane. the lane of a multilane roadway that is used by fast-moving vehicles, as when passing slower traffic.


1 Answers

You set a variable using the = operator, just as you have on line 4. A local variable exists only within the scope where it's created. Assuming the block passed to lane is called before block passed to after_all, then changing the first line to message = nil (so that the variable exists outside the first block's scope) ought to work:

message = nil

lane :alpha do
  message = "[Google Play] Alpha Channel Deployed"
end

after_all |lane, options| do
  slack(message: message)
end
like image 65
Jordan Running Avatar answered Oct 14 '22 06:10

Jordan Running