Search code examples
azurepowershellcontinuous-integrationgithub-actionsazure-cli

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?


Solution

  • 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}}