fastlane: app_store_connect_api_key doesn't work with key_content

New Issue Checklist

Issue Description

When trying to create an app_store_connect_api_key using key_content upload_to_testflight will result in an error. However, providing the key with key_filepath does work.

Command executed
app_store_connect_api_key(
  in_house: true
)

The rest is set with ENV VARS

Complete output when running fastlane, including the stack trace and command used
/usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/spaceship/lib/spaceship/connect_api/token.rb:57:in `initialize': [!] invalid curve name (OpenSSL::PKey::ECError)
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/spaceship/lib/spaceship/connect_api/token.rb:57:in `new'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/spaceship/lib/spaceship/connect_api/token.rb:57:in `create'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/pilot/lib/pilot/manager.rb:33:in `api_token'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/pilot/lib/pilot/manager.rb:20:in `login'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/pilot/lib/pilot/manager.rb:16:in `start'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/pilot/lib/pilot/build_manager.rb:17:in `upload'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/actions/upload_to_testflight.rb:27:in `run'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
	from /usr/local/lib/ruby/gems/2.6.0/gems/fastlane-2.161.0/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
	from Fastfile:28:in `block (2 levels) in parsing_binding'

##[error]Bash exited with code '1'.
Finishing: Run Fastlane Deploy
 I've tried providing the key with and without line breaks but still it didn't seem to make a difference

Environment

 I don't have this, it's running on Azure DevOps

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Oh wait… I did already comment on this about that OMG

I think I will add a base64 encoded option though because why not

@SEGVeenstra I’m glad key_filepath works but key_content should be working too! How are you trying to load it? Are you trying to load it from an environment variable or a string? One thing you will need to make sure that you do is that you keep the new lines (\n) in there.

We should actually probably catch this error and spit out something a bit more useful 🤔

I had this issue… I solved it by doing (fastfile - ruby):

app_store_connect_api_key(
  key_id: "#{ENV["KEY_ID"]}",
  issuer_id: "#{ENV["ISSUER_ID"]}",
  key_content: "#{ENV["KEY_CONTENTS"]}".gsub('\n', '\\n'),
  in_house: false,
)

That gsub function replaces all \n with an escaped \\n… I haven’t tested with Azure, but for Github secrets, we pasted the key exactly as we got it from Apple’s developer portal, and I passed it as an ENV variable to Fastlane from Github secrets…

Then I invoke the above as the very first thing before my build runs. Finally, I do:

upload_to_testflight(
      username: "#{ENV["APPLE_ID"]}",
      app_identifier: "#{ENV["APP_IDENTIFIER"]}",
      app_platform: "ios",
      apple_id: "#{ENV["APPSTORE_APP_ID"]}",
      ipa: "#{ENV["BUILD_NAME"]}.ipa",
      skip_waiting_for_build_processing: true,
      team_id: "#{ENV["TEAM_ID"]}"
    )

Also, note that app_store_connect_api_key is NOT persistent. It must be called before EACH LANE! I tried to have a setup_lane and I called it there… then my other lanes were triggered right after. The other lanes will fail! So I ended up doing:

before_all do
   app_store_connect_api_key(...)
end