Use SSH key from secret in output (::set-output)

Hi,

I declare my parameters with this method :

echo '::set-output name=VAR_NAME::VALUES'

If i use directly SSH key from secret that’s works, but I want use from set-outpout

echo '::set-output name=SSH_KEY::${{ secrets.PRODUCTION_SSH_KEY }}'

With this declaration, I have this authentication error :

drone-scp error:  error copy file to dest: ***, error message: ssh: handshake failed: ssh: unable to authenticate, attempted methods [publickey none], no supported methods remain
1 Like

@theo-stocchetti,

By default, multiline strings is not supported in the value of the output. When you use the multiline strings to set an output, only the string in the first line is recognized as the value of the output.

Due to the SSH private key is multiline strings, so it will be unable to authenticate when you set it as an output.

To solve this problem, you can escape the newline characters (\n, \r) and other special characters (such as ‘%’) in the multiline strings, before setting it as the value of an output.
For example:

    steps:
      - name: Set output
        id: set-output
        run: |
          multi_line="${{ secrets.MY_SSH_PRIVATE_KEY }}"
          multi_line="${multi_line//'%'/'%25'}"
          multi_line="${multi_line//$'\n'/'%0A'}"
          multi_line="${multi_line//$'\r'/'%0D'}"
          
          echo "::set-output name=SSH_KEY::$multi_line"

      - name: Checkout
        uses: actions/checkout@v2.3.3
        with:
          ssh-key: ${{ steps.set-output.outputs.SSH_KEY }}