mbsouksu
mbsouksu

Reputation: 88

Using outputs of Powershell in Github Actions

I am trying to get connection string using Powershell and pass this argument to another step in the actions, but I am getting this error:

Input required and not supplied: connection-string

But I am following a similar behaviour that I use before but I am not sure why it is not working, Here is part of my script:

      - name: Secrets to Key Vault
        uses: azure/powershell@v1
        env:
          POWERSHELL_TELEMETRY_OPTOUT: 1
        with:
          inlineScript: |
            $sqlConnectionString = (az keyvault secret show --vault-name <keyVaultName> --name <secret-name> --query [value] --output tsv)
            echo ::set-output name=sqlConnectionString::$( $sqlConnectionString)
          azPSVersion : '3.1.0'
        

      - name: Deploy Core Module
        uses: azure/sql-action@v1
        id: sqlConnection
        with:
          server-name: <sqlServerName>
          connection-string: ${{ steps.sqlConnection.outputs.sqlConnectionString}}
          dacpac-package: './Database.dacpac'

I think problem is related to the output of the variable but I use similar syntax previously just in a simple run and it worked. Could it be related to the behaviour of the Powershell?

Upvotes: 5

Views: 8161

Answers (2)

baywet
baywet

Reputation: 5342

Since the commands syntax to set the output is now deprecated in GitHub Actions, it can be set using the GITHUB_OUTPUT environment variable. So something like this:

        - name: Secrets to Key Vault
        uses: azure/powershell@v1
        id: setSqlConnection
        env:
          POWERSHELL_TELEMETRY_OPTOUT: 1
        with:
          inlineScript: |
            $sqlConnectionString = (az keyvault secret show --vault-name <keyVaultName> --name <secret-name> --query [value] --output tsv)
            Write-Output "sqlConnectionString=$($sqlConnectionString)" >> $Env:GITHUB_OUTPUT
          azPSVersion : '3.1.0'
      - name: Deploy Core Module
        uses: azure/sql-action@v1
        id: sqlConnection
        with:
          server-name: <sqlServerName>
          connection-string: ${{ steps.setSqlConnection.outputs.sqlConnectionString}}
          dacpac-package: './Database.dacpac'

Note: using the output variable in a later step remains unchanged.

Upvotes: 5

Krzysztof Madej
Krzysztof Madej

Reputation: 40653

Plese add id to you first action:

      - name: Secrets to Key Vault
        uses: azure/powershell@v1
        id: setSqlConnection
        env:
          POWERSHELL_TELEMETRY_OPTOUT: 1
        with:
          inlineScript: |
            $sqlConnectionString = (az keyvault secret show --vault-name <keyVaultName> --name <secret-name> --query [value] --output tsv)
            echo ::set-output name=sqlConnectionString::$( $sqlConnectionString)
          azPSVersion : '3.1.0'
        

      - name: Deploy Core Module
        uses: azure/sql-action@v1
        id: sqlConnection
        with:
          server-name: <sqlServerName>
          connection-string: ${{ steps.setSqlConnection.outputs.sqlConnectionString}}
          dacpac-package: './Database.dacpac'

and then use it to access output ${{ steps.setSqlConnection.outputs.sqlConnectionString}}

Upvotes: 2

Related Questions