Search code examples
github-actionsazure-cli

Azure cant login from github actions


Im trying to deploy from github actions using the following yml:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
        - uses: actions/checkout@v2

        - name: "Login via Azure CLI"
          uses: azure/login@v1
          with:
            client-id: GUID
            tenant-id: GUID
            subscription-id: GUID

but im getting the error: Please check the credentials and make sure az is installed on the runner.

If i change to creds with the json, i get that the credentials are incorrect.

This is how i build the json:

az ad sp create-for-rbac -n "{ADD YOU NAMEW HERE}" --role Contributor --scopes /subscriptions/{subscriptionId} --sdk-auth

thanks


Solution

  • One of the workaround you can follow to resolve the above issue;

    If your project is ready on the GitHub make sure to update the same in your local environment the example.yml file and push them. After creation of credentials using az ad sp create-for-rbac . Store those value into a secret file and pass this as variable in the example.yml file and try to execute as below.

     File: .github/workflows/workflow.yml
    
      on: [push]
    
    name: AzureLoginSample
    
    jobs:
    
      build-and-deploy:
        runs-on: ubuntu-latest
        steps:
        
        - uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
        
        - run: |
            az webapp list --query "[?state=='Running']"
    

    For more information Please refer this GitHub MarketPlace|GitHub Actions for deploying to Azure and this TechCommunity Blog|How to login to Azure with GitHub Actions by @Alfredo Deza.