Preparing build for App Store Connect failed, and the authentication errors weren't why
I released Calorie Burndown 1.0, and the next four Xcode Cloud attempts failed, all on the same commit. The last build before them had uploaded cleanly the day before. The version number in the project was 1.0 both times, and this was the whole error:
Preparing build for App Store Connect failed
No code, no detail. In the runs I looked into, the archive and export steps had succeeded. Then the Archive action went red at the step after them and declined to say why.
In plain English: what is Xcode Cloud?
Apple's build service. You push to a branch, Apple's machines build the app and upload the result to App Store Connect, which is the console where you manage releases. It replaces keeping a Mac plugged in somewhere to do the same job.
The logs describe the part that worked
The downloadable log bundle is the obvious place to look, and for some failures it is the right one. When a Swift expression took too long to type-check in one of my apps, the bundle named the file and the line.
It didn't help here. The preparing step runs after export, and I found nothing from it in the bundles I checked. What I could read was about steps that had gone fine. I have no record of checking whether Xcode Cloud's own web pages show more.
The lines that look like the cause
What the bundle does contain is this pair. I found the first line, then searched the rest of the bundle and found the second:
Unable to authenticate with App Store Connect
Failed to find an account with App Store Connect access for team <id>
That reads like the answer. It is not. I compared the bundle from build 44, which uploaded, with the one from build 47, which didn't. The first line appears twice in each, and the second appears once in each.
The archive logs were no more use. With timestamps and UUIDs normalized, both were 2,301 lines, and my notes from that day say they differed only in the order of parallel build steps.
The missing builds were the clue
The better question was whether a build had arrived at all. The App Store Connect API answers that directly:
GET /v1/apps/{app-id}/builds?limit=200
# follow links.next until there isn't one, then read
# version and processingState for each
Builds 45 to 48 were not there, so there was nothing in processing or
TestFlight to go and debug. That didn't say why they were missing. But 1.0
had gone live before the first of them failed, and the project still said
1.0. I changed MARKETING_VERSION to 1.0.1 as a test, and build
49 uploaded.
Two notes if you try the API. sort is rejected on that endpoint
with PARAMETER_ERROR.ILLEGAL, so sort the results yourself. And
read every page before calling a build missing, because the first page can
leave out the newest ones.
The email names the cause
Apple also emailed the reason that time, with a code on the front. These went into my notes after the fix had already worked. Reading them first might have been quicker:
ITMS-90186: Invalid Pre-Release Train — The train version '1.0' is closed
for new build submissions
ITMS-90062: This bundle is invalid — The value for key
CFBundleShortVersionString [1.0] in the Info.plist file must
contain a higher version than that of the previously approved
version [1.0]
Releasing 1.0 had closed 1.0 to new builds. MARKETING_VERSION
went from valid to invalid without being touched.
In plain English: what is a pre-release train?
All the builds that share one version number — 1.0 build 1, 1.0 build 2, and so on. Publishing that version to customers closes the train, so no further builds may be uploaded under it. The next one has to carry a higher version.
Three days later, a 1.1 build failed with the same error. The last 1.1 build to arrive had uploaded at 20:46 UTC. The next merge's run failed, and the merge after that carried 1.2 and worked. I have neither the exact time 1.1 went live nor an email for that run. That makes the closed train my inference, from the same error and the same fix.
GitHub credentials came under suspicion too. The step that failed runs after the clone, so a failed clone would have stopped the run earlier. The next run cloned the repository and uploaded a build.
The same error, for a different reason
In September, a change to Calorie Burndown removed the purpose string for writing to HealthKit, which the app never asks to do. That seemed safe. The run failed with the same error. I already suspected the missing string, and the email confirmed it:
ITMS-90683: Missing purpose string in Info.plist — ... should contain a
NSHealthUpdateUsageDescription key ...
In plain English: what is a purpose string?
The sentence shown in the prompt asking whether an app may read your health data, location, or photos. Apple requires one for each kind of sensitive data the app is permitted to touch, so you cannot be asked for access without being told what it is for.
It named the key and both bundles, the app and the watch app. Apple's documentation shows an example of this error with two possible triggers. Either the code references APIs that access sensitive data, or "the app has one or more entitlements that permit such access." Calorie Burndown does both, so I can't say which one applied. Never asking to write wasn't enough to make the string optional.
A two-platform app can give you a control
AmbientCast ships on iOS and tvOS from one repository, and a train is closed per platform. When one platform's version was live and the other was still waiting for review, a single run contained its own comparison — same commit, same run:
Archive - iOS FAILED iOS 1.0.1 READY_FOR_SALE
Archive - tvOS SUCCEEDED tvOS 1.0.1 WAITING_FOR_REVIEW
A green archive next to a red one points at something that differs between the platforms, and here that was the version's status. The next day it happened the other way round: tvOS 1.0.2 was live, iOS 1.0.2 was still waiting for review, and only the tvOS archive failed.
My notes from the first of those runs say both internal testing actions read
SKIPPED, even though the tvOS archive had succeeded. Its build
did reach App Store Connect. The iOS build didn't. A skipped action doesn't
tell you whether a build arrived, so check the builds list for each platform.
When the same version went live on both platforms, both archives failed and
only Test stayed green. That looks much worse than it is. A
passing Test doesn't prove the version is the cause, so check
the email too.
What I'd tell you to check first
If Xcode Cloud fails at Preparing build for App Store Connect,
look for Apple's email first. An ITMS code is far easier to search for than
the error Xcode Cloud gives you.
If you can't find one, ask the API which builds arrived. Then check whether the version in your project has already gone live. If it has, it needs a bump whatever else is wrong. Make that bump part of every release, before the next push to your default branch.
And before you act on an alarming line in a log, check whether it also appears in a run that succeeded. I had one from the day before, so that comparison was available from the start.