Fastlane: run a action when another action fails

Created on 5 Jan 2017  路  1Comment  路  Source: fastlane/fastlane

I'm wondering if it is possible to use a sort of try catch in the fast file.

To give an example:

before_all do
    ensure_git_status_clean
    build_number = increment_build_number
  end

if ensure_git_status_clean fails I want to run reset_git_repo to ensure that the repo is clean and so the fast file can continue without any problems.

Is this possible? I can't seem to figure it out.
I'm using Jenkins and when a certain action fails the entire build will fail. I would rather make sure some way this can continue by fixing the error that occurs

question

Most helpful comment

Hi @MaikoHermans 馃憢

Yep, it's definitely possible. 馃憤 You can use the Ruby directives begin, rescue, end to set up your try/catch scenario.

lane :issue do |options|
  begin
    ensure_git_status_clean
  rescue
    reset_git_repo(force: true)
  end
  puts "You're good from here on out!"
end

I did this in the body of a lane but the same thing should work in a before_all block.

_fastlane_ will still note that the ensure_git_status_clean action failed, but you will have prevented that from stopping the _fastlane_ run.

+------+-------------------------+-------------+
|               fastlane summary               |
+------+-------------------------+-------------+
| Step | Action                  | Time (in s) |
+------+-------------------------+-------------+
| 馃挜   | ensure_git_status_clean | 0           |
| 2    | reset_git_repo          | 0           |
+------+-------------------------+-------------+

[16:39:38]: fastlane.tools finished successfully 馃帀

Hope that helps! 馃殌

>All comments

Hi @MaikoHermans 馃憢

Yep, it's definitely possible. 馃憤 You can use the Ruby directives begin, rescue, end to set up your try/catch scenario.

lane :issue do |options|
  begin
    ensure_git_status_clean
  rescue
    reset_git_repo(force: true)
  end
  puts "You're good from here on out!"
end

I did this in the body of a lane but the same thing should work in a before_all block.

_fastlane_ will still note that the ensure_git_status_clean action failed, but you will have prevented that from stopping the _fastlane_ run.

+------+-------------------------+-------------+
|               fastlane summary               |
+------+-------------------------+-------------+
| Step | Action                  | Time (in s) |
+------+-------------------------+-------------+
| 馃挜   | ensure_git_status_clean | 0           |
| 2    | reset_git_repo          | 0           |
+------+-------------------------+-------------+

[16:39:38]: fastlane.tools finished successfully 馃帀

Hope that helps! 馃殌

Was this page helpful?
0 / 5 - 0 ratings