Skip to content

Commit 9448e2f

Browse files
Simran-Blucascosti
andauthored
Actions: Add echo workflow command (#11567)
Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>
1 parent ed42238 commit 9448e2f

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

content/actions/learn-github-actions/workflow-commands-for-github-actions.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ The following table shows which toolkit functions are available within a workflo
6868
| ----------------- | ------------- |
6969
| `core.addPath` | Accessible using environment file `GITHUB_PATH` |
7070
| `core.debug` | `debug` |{% ifversion fpt or ghes > 3.2 or ghae-issue-4929 or ghec %}
71-
| `core.notice` | `notice` |{% endif %}
71+
| `core.notice` | `notice` |{% endif %}
7272
| `core.error` | `error` |
7373
| `core.endGroup` | `endgroup` |
7474
| `core.exportVariable` | Accessible using environment file `GITHUB_ENV` |
7575
| `core.getInput` | Accessible using environment variable `INPUT_{NAME}` |
7676
| `core.getState` | Accessible using environment variable `STATE_{NAME}` |
7777
| `core.isDebug` | Accessible using environment variable `RUNNER_DEBUG` |
7878
| `core.saveState` | `save-state` |
79+
| `core.setCommandEcho` | `echo` |
7980
| `core.setFailed` | Used as a shortcut for `::error` and `exit 1` |
8081
| `core.setOutput` | `set-output` |
8182
| `core.setSecret` | `add-mask` |
@@ -246,6 +247,46 @@ jobs:
246247
247248
{% endraw %}
248249
250+
## Echoing command outputs
251+
252+
```
253+
::echo::on
254+
::echo::off
255+
```
256+
257+
Enables or disables echoing of workflow commands. For example, if you use the `set-output` command in a workflow, it sets an output parameter but the workflow run's log does not show the command itself. If you enable command echoing, then the log shows the command, such as `::set-output name={name}::{value}`.
258+
259+
Command echoing is disabled by default. However, a workflow command is echoed if there are any error occurs processing the command.
260+
261+
The `add-mask`, `debug`, `warning`, and `error` commands do not support echoing because their outputs are already echoed to the log.
262+
263+
You can also enable command echoing globally by turning on step debug logging using the `ACTIONS_STEP_DEBUG` secret. For more information, see "[Enabling debug logging](/actions/managing-workflow-runs/enabling-debug-logging)". In contrast, the `echo` workflow command lets you enable command echoing at a more granular level, rather than enabling it for every workflow in a repository.
264+
265+
### Example toggling command echoing
266+
267+
```yaml
268+
jobs:
269+
workflow-command-job:
270+
runs-on: ubuntu-latest
271+
steps:
272+
- name: toggle workflow command echoing
273+
run: |
274+
echo '::set-output name=action_echo::disabled'
275+
echo '::echo::on'
276+
echo '::set-output name=action_echo::enabled'
277+
echo '::echo::off'
278+
echo '::set-output name=action_echo::disabled'
279+
```
280+
281+
The step above prints the following lines to the log:
282+
283+
```
284+
::set-output name=action_echo::enabled
285+
::echo::off
286+
```
287+
288+
Only the second `set-output` and `echo` workflow commands are included in the log because command echoing was only enabled when they were run. Even though it is not always echoed, the output parameter is set in all cases.
289+
249290
## Sending values to the pre and post actions
250291

251292
You can use the `save-state` command to create environment variables for sharing with your workflow's `pre:` or `post:` actions. For example, you can create a file with the `pre:` action, pass the file location to the `main:` action, and then use the `post:` action to delete the file. Alternatively, you could create a file with the `main:` action, pass the file location to the `post:` action, and also use the `post:` action to delete the file.

0 commit comments

Comments
 (0)