How to write "az cli" script to deploy WebApp in Github

Siegfried Heintze 1,861 Reputation points
2024-05-10T20:26:06.9966667+00:00

Please help me write a script to deploy a blazor server web application whose C# source is in a Github repo. My first choice is "azure CLI" commands inside a "ps1" file.

Attempt #1


Here is my first attempt after having successfully created a webapp plan for the free tier:

az webapp create --name webapp-protected-helloworld --resource-group $env:rg --runtime "dotnet:6" --plan plan-webapp
az webapp deployment source config --repo-url "https://github.com/siegfried01/DemoVisualStudioCICDForBlazorServer001.git" --branch main --name webapp-protected-helloworld --repository-type git --resource-group $env:rg

I get this error message:

 ERROR: Cannot find SourceControlToken with name GitHub.

I tried bing/google searching the error message and even tried edge copilot and could not find any good hints

Attempt #2

I thought well maybe the problem is that my sln and csproj files are not in the top level directory. So I created a new git repo and tried again:

az appservice plan create -g $env:rg -n plan-webapp --sku B1 -l $env:webloc
az webapp create --name HelloBlazorSvr --resource-group $env:rg --plan plan-webapp
az webapp deployment source config --repo-url "https://github.com/siegfried01/HelloBlazorSvr.git" --branch main --name HelloBlazorSvr --repository-type git --resource-group $env:rg

I received this error:

ERROR: Operation returned an invalid status 'OK'

Since the repos I specified are public I think I should not need a github access token.

Thanks

Siegfried

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,001 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,731 Reputation points
    2024-05-10T22:43:09.7333333+00:00

    on the az webapp deployment source config you need to supply a --git-token or use --manual-integration

    note: I typically use GitHub actions to deploy


  2. VenkateshDodda-MSFT 18,951 Reputation points Microsoft Employee
    2024-05-14T06:34:43.2833333+00:00

    @Siegfried Heintze Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    To repro this behavior, I have created an app service and tried to deploy the code by adding the source control using the cmdlet. I am able to link deploy the source code from the repo successfully as well.

    az webapp deployment source config -g <resource-groupname> -n <WebAppName> --repo-url <GithubUrl> --branch <BranchName> --manual-integration
    
    

    As per the cmdlet documentation of az webapp deployment source config --git-token parameter is not a mandatory/required parameter, and this should not break the operation as well.

    Also, --git-token property is not required for the public repositories and the shared cmdlet operation might be failed because of a different reason.

    I would suggest you try using the above shared cmdlet or try running your cmdlet in debug mode by appending --debug at the end.

    Let me know if you are still facing the issue or if you have any further questions on this.