Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: AzurePowerShell@5 does not set environment variables on Windows #20046

Open
5 of 7 tasks
danieljurek opened this issue Jun 20, 2024 · 1 comment
Open
5 of 7 tasks

Comments

@danieljurek
Copy link

danieljurek commented Jun 20, 2024

New issue checklist

Task name

AzurePowerShell@5

Task version

5.241.0

Issue Description

In Linux and MacOS, the following environment variables are available to scripts executed in an AzurePowerShell task:

  • AZURESUBSCRIPTION_SERVICE_CONNECTION_ID
  • AZURESUBSCRIPTION_CLIENT_ID
  • AZURESUBSCRIPTION_TENANT_ID

However, on a Windows agent executing the exact same script, only one variable is available:

  • AZURESUBSCRIPTION_SERVICE_CONNECTION_ID

I would expect to have the client and tenant id also available given that they are available in the Linux/MacOS agents.

This appears to be caused by the fact that the tasks execute differently depending on the platform and the Windows-specific code does not set those environment variables the way that the Linux/MacOS code does.

The Windows-specific code does clear the environment variables (which aren't set) at the end of execution.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows 2022, Windows 2019

Relevant log output

Linux (expected output):

AZURESUBSCRIPTION_SERVICE_CONNECTION_ID: <redacted, valid value>
AZURESUBSCRIPTION_CLIENT_ID: <redacted, valid value>
AZURESUBSCRIPTION_TENANT_ID: <redacted, valid value>

Windows 2019 (note empty strings where valid values are expected):

AZURESUBSCRIPTION_SERVICE_CONNECTION_ID: <redacted, valid value>
AZURESUBSCRIPTION_CLIENT_ID: 
AZURESUBSCRIPTION_TENANT_ID: 

Windows 2022 (note empty strings where valid values are expected):

AZURESUBSCRIPTION_SERVICE_CONNECTION_ID: <redacted, valid value> 
AZURESUBSCRIPTION_CLIENT_ID: 
AZURESUBSCRIPTION_TENANT_ID: 


### Full task logs with system.debug enabled

<details>
  <pre> [REPLACE THIS WITH YOUR INFORMATION] </pre>
</details>


### Repro steps

```yml
steps:
        - task: AzurePowerShell@5
          inputs:
            azureSubscription: !!!REPLACE WITH SERVICE CONNECTION NAME!!!
            azurePowerShellVersion: LatestVersion
            pwsh: true
            ScriptType: InlineScript
            Inline: |
              Write-Host "AZURESUBSCRIPTION_SERVICE_CONNECTION_ID: $($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID)"
              Write-Host "AZURESUBSCRIPTION_CLIENT_ID: $($env:AZURESUBSCRIPTION_CLIENT_ID)"
              Write-Host "AZURESUBSCRIPTION_TENANT_ID: $($env:AZURESUBSCRIPTION_TENANT_ID)"
          displayName: Service connection info
@danieljurek
Copy link
Author

This issue prevents federated auth scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant