Automating Fastlane Authentication for multiple lanes

1.1k views Asked by At

I'm trying to set up Fastfile for upload to Testflight and deliver but for no reason, I can't share my lane_context for app_store_connect_api_key. Here is my Fastfile where I'm wrong.

platform :ios do
   desc "Load ASC API Key information to use in subsequent lanes"
   lane :app_store_connect_api_key do
       app_store_connect_api_key(
       key_id: "key_id",
       issuer_id: "issuerid",
       key_content: "content",
       is_key_content_base64: true,
       duration: 500,
       in_house: false
     )
end
end
  desc "Test auth"
  lane :release do
     app_identifier = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
     api_key = lane_context[SharedValues::APP_STORE_CONNECT_API_KEY]
     pilot(
     api_key: api_key,
     app_identifier: app_identifier,
     skip_submission: true,
     skip_waiting_for_build_processing: true
   )
end

When I'm trying to execute the Fastlane release I receive. Thank you! FastLane Pilot

2

There are 2 answers

3
ridvanaltun On BEST ANSWER

You need execute app_store_connect_api_key before use API key in lane context. Like below:

platform :ios do
   desc "Load ASC API Key information to use in subsequent lanes"
   lane :retrieve_api_key do
       app_store_connect_api_key(
       key_id: "key_id",
       issuer_id: "issuerid",
       key_content: "content",
       is_key_content_base64: true,
       duration: 500,
       in_house: false
     )
end
end
  desc "Test auth"
  lane :release do
     retrieve_api_key
     app_identifier = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
     api_key = lane_context[SharedValues::APP_STORE_CONNECT_API_KEY]
     pilot(
     api_key: api_key,
     app_identifier: app_identifier,
     skip_submission: true,
     skip_waiting_for_build_processing: true
   )
end
0
serhii.syrotynin On

Also, you don't have to specify api_key if it's already in the lane context:

lane :fetch_api_key do

  app_store_connect_api_key(
    key_id: "key_id",
    issuer_id: "issuer_id",
    key_filepath: "key_filepath.p8",
    in_house: false # optional but may be required if using match/sigh
  )
end

desc "Upload to TestFlight"
lane :release do

  fetch_api_key

  pilot(
    ipa: "Your App.ipa", 
    skip_waiting_for_build_processing: true
  )
end

pilot will pick up it automatically