AzurePipelinesPS icon indicating copy to clipboard operation
AzurePipelinesPS copied to clipboard

Authentication failure when using in GitHub Action on Linux agent

Open flcdrg opened this issue 3 years ago • 3 comments

I'm using this module as a step in a GitHub Action workflow.

      - name: Queue build
        env:
          AZURE_DEVOPS_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }}
        shell: pwsh
        run: |
          Install-Module AzurePipelinesPS -Repository PSGallery -Force
          Import-Module AzurePipelinesPS

          $secureToken = ConvertTo-SecureString -String $env:AZURE_DEVOPS_TOKEN -AsPlainText

          Get-APBuildDefinition -Project MyProject -Collection MyCollection -PersonalAccessToken $secureToken -Instance 'https://dev.azure.com/' -ApiVersion '6.0' -DefinitionID 1 -Verbose

If the job that this step runs in has runs-on: ubuntu-latest, then the Get-APBuildDefinition fails (returns the standard html text saying you need to log in).

If I set runs-on: windows-latest then the call succeeds.

Not sure why a Linux runner would cause it to fail

flcdrg avatar Sep 16 '21 04:09 flcdrg

I don't believe ${{ secrets.AZURE_DEVOPS_TOKEN }} resolves to anything. You may be looking for ${{ parameters.AZURE_DEVOPS_TOKEN }}

Dejulia489 avatar Apr 14 '22 13:04 Dejulia489

${{ secrets.AZURE_DEVOPS_TOKEN }} resolves to the secret I have set in my GitHub repository named AZURE_DEVOPS_TOKEN.

The fact that the only change I made was the runs-on line implies that the environment variable is being set correctly.

flcdrg avatar Apr 15 '22 02:04 flcdrg

I would assume this has to do with how the env variables are resolved on a Linux runner vs a windows runner. Can you take the Git Hub action out of the loop and try to run the command directly on your Linux machine?

Dejulia489 avatar Jun 16 '22 15:06 Dejulia489