In general you have two solutions for 2FA with iTunes Connect TestFlight:
Create a CI/bot/“machine” user on iTunes Connect which does not have 2FA enabled, and will only be used for automations, e.g. to use it on bitrise.io. This is probably the easiest solution, as once you create the user it’ll just work, no future changes are required. Simply just register a new iTunes Connect account, just like a regular account, the way you registered your own iTC account, and simply never use it for development / login, only for integrations.
- Follow the official instructions (if any) of the tool you use to do the deploy.
In this case specifically / what the reported issue might be
In this case you can see the
spaceship guide link in the log: https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification
Now, the guide here states that you can run a command locally, and you should provide the output of the command as an environment variable. For environment variables you can use App Env Vars and Secret Env Vars - from the screenshot it seems you used Secret Env Vars. That’s OK, but as you can see in the orange notice Secret Env Vars are not available in pull request builds. This is one thing what might cause the issue for you.
Another thing is, on the screenshot you did set
FASTLANE_SESSION as mentioned in the guide, but you should also make sure to turn off the Replace variables in input? option of that env var, so that Bitrise (CLI) won’t treat the
$ characters in the value as env var references.
Last but not least, and I’d say in your case this is the most likely cause, you should replace the
\n characters in the value printed by
fastlane spaceauth, because if you do provide
\n there, it will be encoded properly to represent the
\ and the
n characters, while what you can see in the fastlane docs is for bash, where
\n means newline. To do this simply replace all the \n with an actual newline (hit enter/return) in the env var value on bitrise.io. That will be the same as if you’d print
\n in bash / the way the fastlane docs expose the env var.