Azure/cli

Run PowerShell scripts in GitHub actions

Closed this issue · 6 comments

fleed commented

It seems that the GitHub action currently supports only bash scripts.
I would like to see support for PowerShell scripts (inline and files) as well.

Hi @fleed Actions already support powershell script by just changing the shell type.

- name: Run powershell
  shell: pwsh
  run: |
         .\build.ps1

On windows, the default is already pwsh so you wont even need to specify that.

fleed commented

@t-dedah could you please provide an example with az commands?
Would it automatically login?

Hi @fleed for login we have another action that you can use

- name: Azure Login
  uses: azure/login@v1
  with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

If you can expand more on the exact requirement then we will be able to provide the exact workflow.

fleed commented

Thank you @t-dedah

In general I'm using PowerShell for all my scripts, so I would like to run some scripts with az commands.
Executing the login as separate action should make it possible, I will try.

@fleed Feel free to reopen the issue

Seems Azure CLI for Azure DevOps supports specifying PowerShell as "scriptType":

# Azure CLI v2
# Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
- task: AzureCLI@2
  inputs:
    azureSubscription: # string. Alias: connectedServiceNameARM. Required. Azure Resource Manager connection. 
    scriptType: # 'ps' | 'pscore' | 'batch' | 'bash'. Required. Script Type. 
    scriptLocation: 'scriptPath' # 'inlineScript' | 'scriptPath'. Required. Script Location. Default: scriptPath.
    scriptPath: # string. Required when scriptLocation = scriptPath. Script Path. 
    #inlineScript: # string. Required when scriptLocation = inlineScript. Inline Script. 
    #arguments: # string. Alias: scriptArguments. Script Arguments. 
    #powerShellErrorActionPreference: 'stop' # 'stop' | 'continue' | 'silentlyContinue'. Optional. Use when scriptType = ps || scriptType = pscore. ErrorActionPreference. Default: stop.
  # Advanced
    #addSpnToEnvironment: false # boolean. Access service principal details in script. Default: false.
    #useGlobalConfig: false # boolean. Use global Azure CLI configuration. Default: false.
    #workingDirectory: # string. Alias: cwd. Working Directory. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.
    #powerShellIgnoreLASTEXITCODE: false # boolean. Optional. Use when scriptType = ps || scriptType = pscore. Ignore $LASTEXITCODE. Default: false.
    #visibleAzLogin: true # boolean. az login output visibility. Default: true.

Would be great if Azure CLI for GitHub actions had all these options too. At least the ability to use PowerShell with azure/CLI@v2.