Azure / Azure/powershell

Action Fails after Login via Az module

Offen
#73 16 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @YanaXu Auf GitHub ansehen
bug idle under-investigation
Vorherrschende Sprache
TypeScript
Sterne
77
Forks
56
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I am using `azure/login@v1` with `enable-AzPSSession: true` to login to azure but the next step `azure/powershell@v1` fails with error:
```
| Your Azure credentials have not been set up or have expired, please run
| Connect-AzAccount to set up your Azure credentials. No certificate
| thumbprint or secret provided for the given service principal
| '***'.
```
My yml is: [here](https://github.com/ptsouk/Policy-as-Code/blob/main/.github/workflows/AzurePowerShellLoginSample.yml)
```
name: AzurePowerShellLoginSample
on:
workflow_dispatch:

jobs:

build:
runs-on: ubuntu-latest
steps:

- name: Login via Az module
uses: azure/login@v1
with:
creds: ${{secrets.POLICY_COMPLIANCE_SCAN}}
allow-no-subscriptions: true
enable-AzPSSession: true

- name: Az PowerShell
uses: azure/powershell@v1
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
if(-not (Get-Module Az.ResourceGraph -ListAvailable))
{
Install-Module Az.ResourceGraph -Scope CurrentUser -Force
}
$query = "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project name, id | sort by name asc"
$subscriptions = Search-AzGraph -Query $query -UseTenantScope
$subscriptions
```

I found a workaround - add a ps cmdlet at the start of the inline script.

So, the following fails:

```
- name: Az PowerShell
uses: azure/powershell@v1
with:
azPSVersion: "latest"
inlineScript: |
if(-not (Get-Module Az.ResourceGraph -ListAvailable))
{
Install-Module Az.ResourceGraph -Scope CurrentUser -Force
}
$query = "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project name, id | sort by name asc"
$subscriptions = Search-AzGraph -Query $query -UseTenantScope
$subscriptions
```
but his one succeeds:
```
- name: Az PowerShell
uses: azure/powershell@v1
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
if(-not (Get-Module Az.ResourceGraph -ListAvailable))
{
Install-Module Az.ResourceGraph -Scope CurrentUser -Force
}
$query = "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project name, id | sort by name asc"
$subscriptions = Search-AzGraph -Query $query -UseTenantScope
$subscriptions
```

I'm looking forward for your help.
Thanks!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.