Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
Hello @Secure Foundations AI
Thanks for providing the detailed troubleshooting. Based on what you've already verified, this doesn't appear to be a simple Bitbucket authorization failure.
The important distinction is that the Bitbucket OAuth flow succeeds and Azure creates a Microsoft.Web/sourcecontrols/Bitbucket resource containing the token, but the subsequent App Service operation:
Microsoft.Web/sites/sourcecontrols/write
fails with:
NotFound - Cannot find SourceControlToken with name Bitbucket
Extended error code: 51004
Azure App Service stores source-control credentials separately from the site-level source-control configuration. Microsoft documents Microsoft.Web/sourcecontrols as the resource containing properties such as the OAuth access token, refresh token, token secret, and expiration time.
Since you've confirmed that the Bitbucket token exists and can be retrieved through the ARM APIs, this suggests the failure occurs when the App Service backend attempts to resolve that token while creating/updating the site's source-control configuration, rather than during Bitbucket authentication itself.
There have also been previous reports of the exact "Cannot find SourceControlToken with name Bitbucket" error during App Service Deployment Center configuration. More recently, users have reported other intermittent failures in the App Service/Bitbucket authorization integration even when the OAuth endpoint successfully returns access and refresh tokens.
I would first try clearing and recreating the cached App Service source-control token using Azure CLI:
az webapp deployment source update-token --git-token ""
Then reauthorize Bitbucket from Deployment Center and attempt the configuration again. Microsoft documents az webapp deployment source update-token specifically for updating or clearing the source-control token cached by Azure App Service.
I would also test whether the failure is tied specifically to Deployment Center by configuring the deployment source through CLI:
az webapp deployment source config \
--name wa-secure-ai-dev \
--resource-group RG-SECUREAI-DEV \
--repo-url <BITBUCKET-REPOSITORY-URL> \
--branch <BRANCH> \
--manual-integration
If the CLI operation returns the same SourceControlToken/51004 error, that would be useful evidence that this isn't simply an Azure Portal UI issue. az webapp deployment source config is Microsoft's supported CLI operation for configuring App Service deployment from a Git repository.
I would not manually modify the Microsoft.Web/sourcecontrols/Bitbucket token resource unless Microsoft Support specifically recommends doing so. Since the OAuth flow is already generating the token correctly, manually replacing it could mask the underlying token-resolution problem.
If clearing/re-authorizing the cached token and configuring through CLI both produce the same 51004 error, I think this warrants review by the Azure App Service/Microsoft.Web engineering team.
Please capture the following from a failed attempt:
- UTC timestamp
- App Service name and Azure region
- Operation/correlation ID from Activity Log
- Full Microsoft.Web/sites/sourcecontrols/write failure
- Extended error code 51004
- Azure CLI --debug output with credentials/tokens removed
Do not post the subscription ID, OAuth access/refresh tokens, or other sensitive values publicly. If a Microsoft moderator needs those details for escalation, they should be exchanged privately.
As a temporary workaround, if Deployment Center remains blocked, you could also use a Bitbucket Pipeline to deploy directly to Azure App Service, rather than relying on App Service's Bitbucket OAuth integration.
Given that authorization, repository enumeration, and branch selection all succeed and the failure occurs specifically during Microsoft.Web/sites/sourcecontrols/write, I would treat this as a source-control token resolution issue within the App Service integration path rather than a basic Bitbucket authorization problem.
Please "Accept the Answer" if this information helped you. This will help us and others in the community as well.