Skip to content

feat: capture stdout and store as output#287

Merged
appleboy merged 25 commits into
appleboy:masterfrom
GammaGames:master
Dec 4, 2024
Merged

feat: capture stdout and store as output#287
appleboy merged 25 commits into
appleboy:masterfrom
GammaGames:master

Conversation

@GammaGames

@GammaGames GammaGames commented Jan 2, 2024

Copy link
Copy Markdown
Contributor

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]
          capture_stdout: 'true'
          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
Copy Markdown
Contributor 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

GammaGames commented Apr 3, 2024

Copy link
Copy Markdown
Contributor Author

fixed conflicts

edit: fixed conflicts

@hasechris

hasechris commented May 21, 2024

Copy link
Copy Markdown

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

@libmilos-so

Copy link
Copy Markdown

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

@GammaGames

Copy link
Copy Markdown
Contributor 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

uchar commented Sep 10, 2024

Copy link
Copy Markdown

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

GammaGames commented Sep 10, 2024

Copy link
Copy Markdown
Contributor 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
Edit: "censoring" values should probably be another pr, maybe another variable you could pass ${{ toJSON(secrets) }} to?

@mikesalvia

Copy link
Copy Markdown

@GammaGames or @appleboy is there any update on when this would be merged in?

@GammaGames

Copy link
Copy Markdown
Contributor Author

@mikesalvia I don't know, but I should probably make it optional and disabled by default first. I started working on that a little today but have yet to test it: https://github.com/GammaGames/ssh-action/tree/capture_vars

@GammaGames GammaGames changed the title Capture stdout and store as output WIP: Capture stdout and store as output Nov 25, 2024
@GammaGames

GammaGames commented Nov 25, 2024

Copy link
Copy Markdown
Contributor Author

Okay it's optional now. Idk why it's not showing in the github action, it's working fine on nektos act and gitea: https://github.com/GammaGames/ssh-action/actions/runs/12017938366/job/33504424638

edit: started discussion asking for help - https://github.com/orgs/community/discussions/145592

@GammaGames GammaGames changed the title WIP: Capture stdout and store as output Capture stdout and store as output Nov 25, 2024
@appleboy

Copy link
Copy Markdown
Owner

I will take it.

Comment thread action.yml
@appleboy

appleboy commented Dec 3, 2024

Copy link
Copy Markdown
Owner

@GammaGames Please help to resolve the conflicts.

@GammaGames

Copy link
Copy Markdown
Contributor Author

Fixed, also changed the test to use true instead of "true" (though both work)

Why remove the script_stop feature?

@appleboy appleboy changed the title Capture stdout and store as output feat: capture stdout and store as output Dec 4, 2024
@appleboy appleboy merged commit 102c0d2 into appleboy:master Dec 4, 2024
@appleboy

appleboy commented Dec 4, 2024

Copy link
Copy Markdown
Owner

@GammaGames Thanks.

Why remove the script_stop feature?

The script_stop function detects each line of instruction, but it cannot handle line breaks using the backslash (). Therefore, I will write another method to solve this problem.

@banagale

banagale commented Dec 4, 2024

Copy link
Copy Markdown

Thank you @GammaGames and all who assisted!

trodemaster added a commit to trodemaster/blakeports that referenced this pull request Sep 15, 2025
- Use envs parameter in ssh-action to capture VM_IP variable
- Add separate step to set GITHUB_OUTPUT with modern approach
- Based on solution from appleboy/ssh-action#287
- This makes VM IP easily accessible to other workflows and jobs
- Proper workflow output mechanism without grepping logs
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

8 participants