How do I return string from fastlane to jenkins groovy variable?

Viewed 359

Have a lane in fastlane as

lane :ipa_path do |options|
 “<ipa path>.ipa”
end

How to store string returned by ipa_path lane in groovy script variable?

2 Answers

In your Fastlane/fastfile

    # Your lane in your fastfile.
    lane :ipa_path do |options|
        ENV["SOME_VAR"] = options[:my_passed_in_option]
        # After calling build_app action to compile/create IPA
        # this lane context value will exist: IPA_OUTPUT_PATH    
        ENV["MY_IPA_PATH"] = lane_context[SharedValues::IPA_OUTPUT_PATH]
    end

In your Jenkinsfile ...

    // Use this in Jenkinsfile.
    stage('Test IPA Path') {
        steps {
           sh "bundle exec ipa_path my_passed_in_option:"some_string_value" --env jenkins"
           sh "echo 'IPA Path is: ${MY_IPA_PATH}" // path_to_IPA_file.IPA
           IPA_PATH = MY_IPA_PATH
           sh "echo 'Some Var is: ${SOME_VAR}" // some_string_value
           SOME_VARIABLE = SOME_VAR
        }
    }

Unfortunately, I don't think there's a way to pass values from fastlane to the parent process. The only way I've found possible so far is to write the string or such to a file.

File.write("output.txt", "your ipa path here")

From there, you can call and set it as environment variable in your server. Something like this:

export MY_ENV=$(cat output.txt)

references: 1, 2

Related