fastlane actions

fastlane actions are the ❤️ of fastlane. Frequently, we use the available actions in our Fastfile passing the required parameters to run it. Run an action from the terminal could be very helpful when we have errors running the action or just because we want to test it.

Available actions

To list in fastlane all the available actions, we need to run in our terminal:

fastlane actions

So the output should reflect all the available actions up to date:

+------------------------------------------+----------------------------------------------------------+-----------------------------+
|                                                    Available fastlane actions                                                     |
+------------------------------------------+----------------------------------------------------------+-----------------------------+
| Action                                   | Description                                              | Author                      |
+------------------------------------------+----------------------------------------------------------+-----------------------------+
| adb                                      | Run ADB Actions                                          | hjanuschka                  |
| adb_devices                              | Get an array of Connected android device serials         | hjanuschka                  |
| add_extra_platforms                      | Modify the default list of supported platforms           | lacostej                    |
| add_git_tag                              | This will add an annotated git tag to the current        | Multiple                    |
|                                          | branch                                                   |                             |
| app_store_build_number                   | Returns the current build_number of either live or edit  | hjanuschka                  |
|                                          | version                                                  |                             |
...

Action documentation

Now we have all the available actions if we want to see the documentation about one of these we run in our terminal:

fastlane action [action_name]

For example, let’s get the docs for the action unlock_keychain running in our terminal:

fastlane action unlock_keychain

So we should get all the documentation about the specified action:

Loading documentation for unlock_keychain:

+--------------------------------------------------------------------------+
|                             unlock_keychain                              |
+--------------------------------------------------------------------------+
| Unlock a keychain                                                        |
|                                                                          |
| Unlocks the given keychain file and adds it to the keychain search list. |
| Keychains can be replaced with `add_to_search_list: :replace`.           |
|                                                                          |
| Created by xfreebird                                                     |
+--------------------------------------------------------------------------+

+--------------------+-----------------------------+---------------------------------------+---------+
|                                      unlock_keychain Options                                       |
+--------------------+-----------------------------+---------------------------------------+---------+
| Key                | Description                 | Env Var                               | Default |
+--------------------+-----------------------------+---------------------------------------+---------+
| path               | Path to the keychain file   | FL_UNLOCK_KEYCHAIN_PATH               |         |
| password           | Keychain password           | FL_UNLOCK_KEYCHAIN_PASSWORD           |         |
| add_to_search_list | Add to keychain search list | FL_UNLOCK_KEYCHAIN_ADD_TO_SEARCH_LIST | true    |
| set_default        | Set as default keychain     | FL_UNLOCK_KEYCHAIN_SET_DEFAULT        | false   |
+--------------------+-----------------------------+---------------------------------------+---------+
* = default value is dependent on the user's system

More information can be found on https://docs.fastlane.tools/actions/unlock_keychain

We can see the key, description, environment variable name and default value of each parameter, and a link to fastlane docs for more information about the action.

Run the action from the terminal

Now we have all the actions available and its docs we can see how to run the actions directly from your terminal. To run an action from the terminal we can run the following command in our terminal:

fastlane run #action_name

fastlane should start asking for the parameters required to run the action. Let’s see in action run it the action unlock_keychain:

fastlane run unlock_keychain

After executing the action with the required parameters successfully we should see the result of the action:

-----------------------------
--- Step: unlock_keychain ---
-----------------------------
To not be asked about this value, you can specify it using 'path'
Path to the keychain file: /Users/username/Library/Keychains/login.keychain-db
To not be asked about this value, you can specify it using 'password'
Keychain password: ****************
Unlocking keychain at path: /Users/username/Library/Keychains/login.keychain-db
Result: [nil, "", ""]

That is great! However, what if we want to pass parameters when we run the action directly? Well, fastlane have options for it too 👍.

Passing parameters to actions from your console

To pass parameters from the terminal to the action we can specify parameter:value for each one of the parameters. Let’s see in action running the following command from the terminal:

fastlane run unlock_keychain path:/Users/username/Library/Keychains/login.keychain-db password:*******

The action should work without requiring the required parameters. Nevertheless, according to the fastlane docs, there are some cases when might not be able to set some parameters using this method.

Another workaround and a solution to the parameters were not able to set directly while running the action is to set the environment variables returned in the docs about the action before running the lane. We can do this using the export command in the terminal running the following:

export FL_UNLOCK_KEYCHAIN_PATH=/Users/username/Library/Keychains/login.keychain-db
export FL_UNLOCK_KEYCHAIN_PASSWORD=*******

In that way when we run the action, the values would be available. The environment variables set only will be available while the terminal session exists, try to use always the solution passing the parameters.

Conclusion

We covered how to run fastlane actions from the terminal and how to pass parameters to the actions.

Thanks for reading! 🎉.

· swift, ios, fastlane