skip to Main Content

When I try to set up continuous deployment through GitHub Actions on an App Service (either a Asp.NET app or a Node app), I get a Failed to set up deployment: Cannot find SourceControlToken with name GitHub error.

I’ve ensured Azure App Service is authorized on my account’s authorized OAuth Apps, but I haven’t found any further instructions on whether there are any settings I must change on Github’s side.

What I found here on SO was Deploying website from private Github repository using ARM Templates, that pointed me to check whether there’s a token set on /providers/Microsoft.Web/sourcecontrols/GitHub resource, which there is (token obscured by me of course):

{
  "id": null,
  "name": "GitHub",
  "type": "Microsoft.Web/sourcecontrols",
  "properties": {
    "name": "GitHub",
    "token": "***************************************",
    "tokenSecret": null,
    "refreshToken": null,
    "environment": null
  }
}

The same also happens if I try and set up CD with the App Service Build Service. I’ve tried changing the token already there for a new fresh token I manually generated on Github, but still, no go. The same happens with a different Github account as well. How should I set up CD for my Azure App Service?

2

Answers


  1. Check the below steps for Continuous deployment of Azure Web Apps.

    • In Azure Portal Create an App Service.
      enter image description here

    • Create a Node JS App from either VSCode or Visual Studio and push the source to GitHub Repository.

    • From Deployment Center => Settings =>select the Source GitHub Under Continuous Deployment.

    • We need to Authorize the GitHub Account and select the correct repository and branch.
      enter image description here

    • Once we connect to the GitHub a new folder .github/workflows will be created with the workflow(yaml file).

    My Yml file*

    
    name: Build and deploy Node.js app to Azure Web App - NodeApp6Dec
    
    on:
      push:
        branches:
          - master
      workflow_dispatch:
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v2
    
          - name: Set up Node.js version
            uses: actions/setup-node@v1
            with:
              node-version: '16.x'
    
          - name: npm install, build, and test
            run: |
              npm install
              npm run build --if-present
              npm run test --if-present
    
          - name: Upload artifact for deployment job
            uses: actions/upload-artifact@v2
            with:
              name: node-app
              path: .
    
      deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
          name: 'production'
          url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
        steps:
          - name: Download artifact from build job
            uses: actions/download-artifact@v2
            with:
              name: node-app
    
          - name: 'Deploy to Azure Web App'
            id: deploy-to-webapp
            uses: azure/webapps-deploy@v2
            with:
              app-name: 'NodeApp6Dec'
              slot-name: 'production'
              publish-profile: ${{ secrets.AzureAppService_PublishProfile_acc907cfa07 }}
              package: .
    

    OutPut:

    enter image description here

    • If you want to make any changes to the yml file, go to the GitHub Repository => Workflows => .github/workflows folder => click on the file and edit.
      enter image description here

    Failed to set up deployment: Cannot find SourceControlToken with name GitHub

    • As mentioned above we need to authorize the GitHub Account. Also make sure AzureApp service is registered in Authorized OAuth Apps in GitHub.

    In your GitHub Account => in the right paneSettings => left pane applications => Authorized OAuth Apps.

    enter image description here

    Login or Signup to reply.
  2. Try running this in azure console (terminal-looking icon on top right).

    Set-AzResource -PropertyObject @{token=$github_pat} -ResourceId /providers/Microsoft.Web/sourcecontrols/GitHub
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search