Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture stdout and store as output #287

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GammaGames
Copy link

@GammaGames GammaGames commented Jan 2, 2024

Possibly fixes #274, #38

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: SSH
        id: ssh
        uses: https://github.com/GammaGames/ssh-action@master
        with:
          host: [fill in]
          script: |
            ls -l ~/test/
      - name: echo
        run: echo "${{ steps.ssh.outputs.stdout }}"

If successful, it has the following in steps.ssh.outputs.stdout:

======CMD======
ls -l ~/test/
======END======
out: total 0
out: -rw-rw-r-- 1 user group 0 Jan  2 14:24 file1
out: -rw-rw-r-- 1 user group 0 Jan  2 14:24 file2
==============================================
✅ Successfully executed commands to all host.
==============================================

On error it acts like it does now.

@GammaGames
Copy link
Author

One potential issue is that secrets aren't masked in the output variable like they are in the log. I was able to fix it with a filtering step, but it's manual:

- uses: mad9000/actions-find-and-replace-string@4
  id: filter
  with:
    source: ${{ steps.ssh.outputs.stdout }}
    find: '${{ secrets.value }}'
    replace: '***'
    replaceAll: true
- run: echo '${{ steps.filter.outputs.value }}'

@GammaGames
Copy link
Author

GammaGames commented Apr 3, 2024

fixed conflicts

edit: fixed conflicts

@hasechris
Copy link

hasechris commented May 21, 2024

@appleboy
Could you take a look at this? Having an output would be great

@Digital-Lemon
Copy link

I'd add a variable to enable (or disable) this behavior, as sometimes the outputs could be huge

@GammaGames
Copy link
Author

Good point, it should probably also not capture by default because the output has all command output (without censoring, like the gh step interface has)

@uchar
Copy link

uchar commented Sep 10, 2024

I think the script should handle masking secrets by itself , not very good practice to depend on another step for doing it , this can cause security issues if some one forget it

@GammaGames
Copy link
Author

I agree! Is there a way to get secret names at runtime? I was under the impression that github action output is filtered before displaying, but doesn't have any filtering on the server side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example of how to use this and get output of one or more lines to $GITHUB_OUTPUT
4 participants