Fastlane using Swift | Passing parameters | CI

Dumitru Vilceanu
4 min readApr 10, 2018

--

This post assumes that you are familiar with Fastlane already.
Here you can find how you can pass parameters to a lane.

My scenario: In my CI setup, I am using Jenkins along with Fastlane. For that reason I need to send parameters from command line to my lane.
After having a hard time figuring out how can I pass parameters from command line to Fastlane I finally figure it out.
What was missing??…..Well.. documentation.
I have started my investigation from the following points:

https://github.com/fastlane/fastlane/issues/11747
https://github.com/fastlane/fastlane/issues/11370
https://github.com/fastlane/fastlane/pull/11401

Prerequisites:
1. Install fastlane on your MacOS
2. Set it up using:

bundler exec fastlane init swift

At this moment fastlane is creating some default files inside the project folder.
(fastlane folder, Gemfile and Gemfile.lock)

From this moment we need to focus on extending the Fastfile.swift. For this I prefered to use FastlaneSwiftRunner.xcodeproj located at:
./fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj
After analysing the swift source files of Fastlane I have tried to see how can I call a lane from command line without & with parameters.
I have defined some sample functions (lanes) in my Fastfile.swift:
(I have decided to give it some of these formats according to the fastlane swift code).

⚠️ Lane name matching is case insensitive. Very nice !

At first glance I discovered that I can call firstLane using two type of formats:
bundle exec fastlane firstLane or bundle exec fastlane first

Next step would have been to see how can I pass a parameter to a lane. Without going into a complex Fastfile I wanted to send just a sample [key:value] format.

Of course for secondLane we could not use the following command:

bundle exec fastlane secondLane

So, after in depth investigation, I managed to find out which formats were correct, why, and how can you pass parameters. As it can be seen from previous console message, only 3 methods were detected as lanes.

// simple lane without parameters, having “lane” as suffix.
func firstLane()
// lane with parameters, as optional, having “lanewithoptions:” as suffix
func thirdLane(withOptions options:[String: String]?)
// lane with parameters, as optional, having “lanewithoptions:” as suffix
func fourthLaneWithOptions(_ options:[String: String]?)

Even if in the console is not clear enough, having “lanewithoptions:” as suffix is the reason why these functions were detected as lanes.

So lets try to see if the param is sent properly.
For this test, I have added a fatalError call in order to stop execution.
This allows to get feedback right away in the console.
So, thirdLane has been updated to:

After running:

bundle exec fastlane third environment:Staging
I got the following result (which means the parameter was sent properly):

After running

bundle exec fastlane third environment:Production

I got the following result (which means the parameter was sent properly):

Conclusion:
One example (which I find easy to read) for having a lane with parameters is:

and an example how to call it following command line would be:

bundle exec fastlane hockeyApp environment:Staging

Resources:
https://github.com/doruvil/FastlaneSwift/tree/testing-fastlane-swift-limits

P.S.:
I have opened an issue in order to fix the matching of the functions to the list of available lanes:
https://github.com/fastlane/fastlane/issues/12277

Please share your thoughts, or things you might find it difficult / not possible when setting up fastlane.

--

--