* Empty commit * updated beta note for GHAE * more GHAE update + resolve conflict * more GHAE updates + prepare for screenshots * Apply suggestions from code review Co-authored-by: Shati Patel <42641846+shati-patel@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Shati Patel <42641846+shati-patel@users.noreply.github.com> * address remaining review comments * Revise "About GitHub AE" (#17679) * add screenshots to the Configuring article * reworked to have a separate GHAE section * list numbering * more work on screenshots and conditions * add GHAE screenshots in article * review screenshots in article * added more screenshots and updated more articles * screenshot madness * fix liquid versioning * refactor the ghae script * [GHAE CB/Feb 22]: Add article about data residency for GitHub AE (#17847) * add missing GHAE versioning to article * move screenshots to GHAE asset directory * forgot to change the path for these two images * replace CBB screenshot + add better screenshot * [GHAE CB/Feb 22]: Document upgrades for GitHub AE (#17848) * Version article for GitHub AE * Replace unused variable * Incorporate reviewer feedback * Update intro Co-authored-by: Ethan P <56270045+ethanpalm@users.noreply.github.com> * [GHAE] Enable IP allow list (#17691) * Notes for CC * Updat permission leves chart * Add updated article to further reading * Update gated feature callout with GitHub AE * Version "Managing allowed IP addresses for your organization" for AE * Update images * Update "Restricting network traffic to your enterprise" with new procedures * remove todo note * Update audited actions * Update info about Premium Runners * Use reusable for Premium Runners * Change "Premium Runners" to "AE hosted runners" * Incorporate reviewer feedback * Use correct reusable * Version reusable correctly * [Feb 22] GHAE: Code scanning beta (#17830) * Add "github-ae" to all the frontmatter * GHAE-ify the reusables * Add some more changes * Re-use some content * 🔪 Semmle links * Revert change re "--external-repository-token" in the CodeQL runner * Update CodeQL runner token scopes * Update two screenshots * Remove mention of GitHub.com from AE + other fixes * Apply suggestions from code review Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com> * Use `product_name` variable instead of `product_location` * Remove confusing phrase * [Feb 22] GHAE: Code scanning API and webhook docs (#17883) * Version API and webhook docs * Actually add versioning for GHAE * Fix anchor * [TEMPORARY] Preview for API endpoints * Revert API previews * Update procedure step Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com> * Update docs for AzureAD Group SCIM support in GHAE (#17892) * [GHAE CB] SMTP bootstrapping flow (#17888) * draft * update with AE conntent * update with tons of versioning * remove that lie * fill out the rest of these steps * update with correct versioning * more edits * add images * reversion most of ae article * fix versioning * format correctlly * words matter * last image * update with permmissions * update versioning * add link * apply feedback ❤️ * update with differrent spacing * update with feedback * more feedback * Temporary GHAE release notes for consumables beta launch (#17859) * Create release-notes.md * Add frontmatter * Add to index file * Update github-ae-release-notes.md * Add release notes from Google Doc * Update finalized docs links that have been reviewed * OAuth device flow link update * version for AE * few fixes * Update content/admin/overview/github-ae-release-notes.md * small edits * whoops * commit * update with different links * used wrong reusable * fix more brokenness * Update repository-references.js * Update repository-references.js Co-authored-by: Meg Bird <megbird@github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> * [GHAE] Audit public repos (#17917) * verifying what we mean by public * Apply suggestions from code review * Update content/developers/apps/installing-github-apps.md Co-authored-by: Laura Coursen <lecoursen@github.com> * fixing placememnt of liquid conditional Co-authored-by: Laura Coursen <lecoursen@github.com> * GHAE packages beta (#17786) Co-authored-by: jmarlena <6732600+jmarlena@users.noreply.github.com> Co-authored-by: Martin Lopes <martin389@github.com> * fix broken links * [GHAE CB/March 01]: GitHub Actions on GHAE (beta) (#17725) * Added initial layout for premium runners * Restructured content * Added placeholder for removing premium runner * Added versioning and warning note for self-hosted runners * Added versioning and beta notice for actions content * Rephrased beta note * Added versioning for API docs, fixes * Added versioning fixes * Split Github-hosted and premium topics into separate articles * Added edits * Restructured some topics * Revised "Using premium runners in a workflow" * Some small fixes * Fixed typo * Added fixes to reusable * Added edits * Made section titles consistent * Added billing, group mgmt, reusable steps * Cropped certain screenshots for future-proofing * Removed superfluous reusable * Added fixes * Revert "Cropped certain screenshots for future-proofing" This reverts commit c7f24f31fa30d4fe3de2b63fc3cd5feba44ef518. * Added new section for custom images * Added versioning for enterprise-admin operations * Added edits * Added edits * Update adding-premium-runners.md * Removed SHR screenshots. Intending to update them when UI is available. * Update using-labels-with-premium-runners.md * Added custom labels section * Added preview of API docs changes * Added versioning for ip allow list section * Removed removal article * Renamed premium runners to AE hosted runners * Re-added added API preview * Fixed links, updated software specs * Revised "Software specifications" based on feedback * Fixed typos * Small fixes * Added new article "Creating custom images" * Moved "Creating custom images" link * Apply suggestions from code review Co-authored-by: ahdbilal <55514721+ahdbilal@users.noreply.github.com> * Added update from review * Added updates from tech review * Apply suggestions from code review Co-authored-by: ahdbilal <55514721+ahdbilal@users.noreply.github.com> * Added updates from tech review * Added updates from tech review * Added updates from tech review * Added updates from tech review * Fixed reusable * Added fixes * Added update from tech review * Removed the dereferenced OpenAPI schema files * Added fixes * Fixed links * Fixed links * Apply suggestions from code review Co-authored-by: jmarlena <6732600+jmarlena@users.noreply.github.com> * Added updates from peer review * Removed sections that are not in beta * Update viewing-your-github-actions-usage.md * Update viewing-job-execution-time.md * Update index.md * Update about-github-hosted-runners.md * Restored versioning to match GHES approach * Fixed link * Restored self-hosted runner reference to UI steps. * Updated screenshots * Updated screenshots and procedures * Small edits to screenshots * Added AE url info for SHR * Removed superfluous versioning * Update security-hardening-for-github-actions.md * Update actions-shared.md * Small edits * Update usage-limits-billing-and-administration.md * Update managing-complex-workflows.md * Additional versioning * Additional versioning * version environments api and checkrun deployments for ghae (#17991) Co-authored-by: Martin Lopes <martin389@github.com> * Update reviewing-the-audit-log-for-your-organization.md * Added versioning for enterprise policy settings * version configuring artifact retention for AE * remove AE versioning for connecting to Marketplace * Apply suggestions from code review Co-authored-by: Joe Bourne <thejoebourneidentity@github.com> * Update content/admin/github-actions/getting-started-with-github-actions-for-github-ae.md Co-authored-by: Joe Bourne <thejoebourneidentity@github.com> * rewording not public to private * fixing liquid * Fixed elseif entries * Added expectations note * Revised label management article for AE hosted runners * Added enterprise-admin note for adding AE hosted runners * Update enterprise-admin.md * Update self-hosted-runner-security.md * Versioned reusable for AE * Empty commit for CI Co-authored-by: ahdbilal <55514721+ahdbilal@users.noreply.github.com> Co-authored-by: jmarlena <6732600+jmarlena@users.noreply.github.com> Co-authored-by: skedwards88 <skedwards88@github.com> Co-authored-by: Leona B. Campbell <3880403+runleonarun@users.noreply.github.com> Co-authored-by: Joe Bourne <thejoebourneidentity@github.com> Co-authored-by: runleonarun <runleonarun@github.com> * Update OpenAPI Descriptions for GHAE * Update content/admin/overview/github-ae-release-notes.md Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com> Co-authored-by: mchammer01 <42146119+mchammer01@users.noreply.github.com> Co-authored-by: Shati Patel <42641846+shati-patel@users.noreply.github.com> Co-authored-by: shati-patel <shati-patel@github.com> Co-authored-by: Sarah Schneider <sarahs@github.com> Co-authored-by: skedwards88 <skedwards88@github.com> Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com> Co-authored-by: Felicity Chapman <felicitymay@github.com> Co-authored-by: Meg Bird <megbird@github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: Leona B. Campbell <3880403+runleonarun@users.noreply.github.com> Co-authored-by: Laura Coursen <lecoursen@github.com> Co-authored-by: jmarlena <6732600+jmarlena@users.noreply.github.com> Co-authored-by: Martin Lopes <martin389@github.com> Co-authored-by: ahdbilal <55514721+ahdbilal@users.noreply.github.com> Co-authored-by: Joe Bourne <thejoebourneidentity@github.com> Co-authored-by: runleonarun <runleonarun@github.com> Co-authored-by: github-openapi-bot <69533958+github-openapi-bot@users.noreply.github.com>
324 lines
12 KiB
Markdown
324 lines
12 KiB
Markdown
---
|
|
title: Workflow commands for GitHub Actions
|
|
shortTitle: Workflow commands
|
|
intro: You can use workflow commands when running shell commands in a workflow or in an action's code.
|
|
product: '{% data reusables.gated-features.actions %}'
|
|
redirect_from:
|
|
- /articles/development-tools-for-github-actions
|
|
- /github/automating-your-workflow-with-github-actions/development-tools-for-github-actions
|
|
- /actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions
|
|
- /actions/reference/development-tools-for-github-actions
|
|
- /actions/reference/logging-commands-for-github-actions
|
|
versions:
|
|
free-pro-team: '*'
|
|
enterprise-server: '>=2.22'
|
|
github-ae: '*'
|
|
---
|
|
|
|
{% data reusables.actions.enterprise-beta %}
|
|
{% data reusables.actions.enterprise-github-hosted-runners %}
|
|
{% data reusables.actions.ae-beta %}
|
|
|
|
### About workflow commands
|
|
|
|
Actions can communicate with the runner machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks.
|
|
|
|
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
|
Most workflow commands use the `echo` command in a specific format, while others are invoked by writing to a file. For more information, see ["Environment files".](#environment-files)
|
|
{% else %}
|
|
Workflow commands use the `echo` command in a specific format.
|
|
{% endif %}
|
|
|
|
``` bash
|
|
echo "::workflow-command parameter1={data},parameter2={data}::{command value}"
|
|
```
|
|
|
|
{% note %}
|
|
|
|
**Note:** Workflow command and parameter names are not case-sensitive.
|
|
|
|
{% endnote %}
|
|
|
|
{% warning %}
|
|
|
|
**Warning:** If you are using Command Prompt, omit double quote characters (`"`) when using workflow commands.
|
|
|
|
{% endwarning %}
|
|
|
|
### Using workflow commands to access toolkit functions
|
|
|
|
The [actions/toolkit](https://github.com/actions/toolkit) includes a number of functions that can be executed as workflow commands. Use the `::` syntax to run the workflow commands within your YAML file; these commands are then sent to the runner over `stdout`. For example, instead of using code to set an output, as below:
|
|
|
|
```javascript
|
|
core.setOutput('SELECTED_COLOR', 'green');
|
|
```
|
|
|
|
You can use the `set-output` command in your workflow to set the same value:
|
|
|
|
{% raw %}
|
|
``` yaml
|
|
- name: Set selected color
|
|
run: echo '::set-output name=SELECTED_COLOR::green'
|
|
id: random-color-generator
|
|
- name: Get color
|
|
run: echo "The selected color is ${{ steps.random-color-generator.outputs.SELECTED_COLOR }}"
|
|
```
|
|
{% endraw %}
|
|
|
|
The following table shows which toolkit functions are available within a workflow:
|
|
|
|
| Toolkit function | Equivalent workflow command |
|
|
| ----------------- | ------------- |
|
|
| `core.addPath` | {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}Accessible using environment file `GITHUB_PATH`{% else %} `add-path` {% endif %} |
|
|
| `core.debug` | `debug` |
|
|
| `core.error` | `error` |
|
|
| `core.endGroup` | `endgroup` |
|
|
| `core.exportVariable` | {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}Accessible using environment file `GITHUB_ENV`{% else %} `set-env` {% endif %} |
|
|
| `core.getInput` | Accessible using environment variable `INPUT_{NAME}` |
|
|
| `core.getState` | Accessible using environment variable `STATE_{NAME}` |
|
|
| `core.isDebug` | Accessible using environment variable `RUNNER_DEBUG` |
|
|
| `core.saveState` | `save-state` |
|
|
| `core.setFailed` | Used as a shortcut for `::error` and `exit 1` |
|
|
| `core.setOutput` | `set-output` |
|
|
| `core.setSecret` | `add-mask` |
|
|
| `core.startGroup` | `group` |
|
|
| `core.warning` | `warning file` |
|
|
|
|
{% if currentVersion ver_lt "enterprise-server@2.23" %}
|
|
### Setting an environment variable
|
|
|
|
`::set-env name={name}::{value}`
|
|
|
|
Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::set-env name=action_state::yellow"
|
|
```
|
|
{% endif %}
|
|
|
|
### Setting an output parameter
|
|
|
|
`::set-output name={name}::{value}`
|
|
|
|
Sets an action's output parameter.
|
|
|
|
Optionally, you can also declare output parameters in an action's metadata file. For more information, see "[Metadata syntax for {% data variables.product.prodname_actions %}](/articles/metadata-syntax-for-github-actions#outputs)."
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::set-output name=action_fruit::strawberry"
|
|
```
|
|
|
|
{% if currentVersion ver_lt "enterprise-server@2.23" %}
|
|
### Adding a system path
|
|
|
|
`::add-path::{path}`
|
|
|
|
Prepends a directory to the system `PATH` variable for all subsequent actions in the current job. The currently running action cannot access the new path variable.
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::add-path::/path/to/dir"
|
|
```
|
|
{% endif %}
|
|
|
|
### Setting a debug message
|
|
|
|
`::debug::{message}`
|
|
|
|
Prints a debug message to the log. You must create a secret named `ACTIONS_STEP_DEBUG` with the value `true` to see the debug messages set by this command in the log. For more information, see "[Enabling debug logging](/actions/managing-workflow-runs/enabling-debug-logging)."
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::debug::Set the Octocat variable"
|
|
```
|
|
|
|
### Setting a warning message
|
|
|
|
`::warning file={name},line={line},col={col}::{message}`
|
|
|
|
Creates a warning message and prints the message to the log. You can optionally provide a filename (`file`), line number (`line`), and column (`col`) number where the warning occurred.
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::warning file=app.js,line=1,col=5::Missing semicolon"
|
|
```
|
|
|
|
### Setting an error message
|
|
|
|
`::error file={name},line={line},col={col}::{message}`
|
|
|
|
Creates an error message and prints the message to the log. You can optionally provide a filename (`file`), line number (`line`), and column (`col`) number where the error occurred.
|
|
|
|
#### Example
|
|
|
|
``` bash
|
|
echo "::error file=app.js,line=10,col=15::Something went wrong"
|
|
```
|
|
|
|
### Grouping log lines
|
|
|
|
```
|
|
::group::{title}
|
|
::endgroup::
|
|
```
|
|
|
|
Creates an expandable group in the log. To create a group, use the `group` command and specify a `title`. Anything you print to the log between the `group` and `endgroup` commands is nested inside an expandable entry in the log.
|
|
|
|
#### Example
|
|
|
|
```bash
|
|
echo "::group::My title"
|
|
echo "Inside group"
|
|
echo "::endgroup::"
|
|
```
|
|
|
|

|
|
|
|
### Masking a value in log
|
|
|
|
`::add-mask::{value}`
|
|
|
|
Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is replaced with the `*` character. You can use an environment variable or string for the mask's `value`.
|
|
|
|
#### Example masking a string
|
|
|
|
When you print `"Mona The Octocat"` in the log, you'll see `"***"`.
|
|
|
|
```bash
|
|
echo "::add-mask::Mona The Octocat"
|
|
```
|
|
|
|
#### Example masking an environment variable
|
|
|
|
When you print the variable `MY_NAME` or the value `"Mona The Octocat"` in the log, you'll see `"***"` instead of `"Mona The Octocat"`.
|
|
|
|
```bash
|
|
MY_NAME="Mona The Octocat"
|
|
echo "::add-mask::$MY_NAME"
|
|
```
|
|
|
|
### Stopping and starting workflow commands
|
|
|
|
`::stop-commands::{endtoken}`
|
|
|
|
Stops processing any workflow commands. This special command allows you to log anything without accidentally running a workflow command. For example, you could stop logging to output an entire script that has comments.
|
|
|
|
#### Example stopping workflow commands
|
|
|
|
``` bash
|
|
echo "::stop-commands::pause-logging"
|
|
```
|
|
|
|
To start workflow commands, pass the token that you used to stop workflow commands.
|
|
|
|
`::{endtoken}::`
|
|
|
|
#### Example starting workflow commands
|
|
|
|
``` bash
|
|
echo "::pause-logging::"
|
|
```
|
|
|
|
### Sending values to the pre and post actions
|
|
|
|
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.
|
|
|
|
If you have multiple `pre:` or `post:` actions, you can only access the saved value in the action where `save-state` was used. For more information on the `post:` action, see "[Metadata syntax for {% data variables.product.prodname_actions %}](/actions/creating-actions/metadata-syntax-for-github-actions#post)."
|
|
|
|
The `save-state` command can only be run within an action, and is not available to YAML files. The saved value is stored as an environment value with the `STATE_` prefix.
|
|
|
|
This example uses JavaScript to run the `save-state` command. The resulting environment variable is named `STATE_processID` with the value of `12345`:
|
|
|
|
``` javascript
|
|
console.log('::save-state name=processID::12345')
|
|
```
|
|
|
|
The `STATE_processID` variable is then exclusively available to the cleanup script running under the `main` action. This example runs in `main` and uses JavaScript to display the value assigned to the `STATE_processID` environment variable:
|
|
|
|
``` javascript
|
|
console.log("The running PID from the main action is: " + process.env.STATE_processID);
|
|
```
|
|
|
|
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
|
## Environment Files
|
|
|
|
During the execution of a workflow, the runner generates temporary files that can be used to perform certain actions. The path to these files are exposed via environment variables. You will need to use UTF-8 encoding when writing to these files to ensure proper processing of the commands. Multiple commands can be written to the same file, separated by newlines.
|
|
|
|
{% warning %}
|
|
|
|
**Warning:** Powershell does not use UTF-8 by default. Make sure you write files using the correct encoding. For example, you need to set UTF-8 encoding when you set the path:
|
|
|
|
```yaml
|
|
steps:
|
|
- run: echo "mypath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
```
|
|
|
|
{% endwarning %}
|
|
|
|
### Setting an environment variable
|
|
|
|
`echo "{name}={value}" >> $GITHUB_ENV`
|
|
|
|
Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.
|
|
|
|
#### Example
|
|
|
|
{% raw %}
|
|
```
|
|
steps:
|
|
- name: Set the value
|
|
id: step_one
|
|
run: |
|
|
echo "action_state=yellow" >> $GITHUB_ENV
|
|
- name: Use the value
|
|
id: step_two
|
|
run: |
|
|
echo "${{ env.action_state }}" # This will output 'yellow'
|
|
```
|
|
{% endraw %}
|
|
|
|
#### Multiline strings
|
|
|
|
For multiline strings, you may use a delimiter with the following syntax.
|
|
|
|
```
|
|
{name}<<{delimiter}
|
|
{value}
|
|
{delimiter}
|
|
```
|
|
|
|
##### Example
|
|
|
|
In this example, we use `EOF` as a delimiter and set the `JSON_RESPONSE` environment variable to the value of the curl response.
|
|
```yaml
|
|
steps:
|
|
- name: Set the value
|
|
id: step_one
|
|
run: |
|
|
echo 'JSON_RESPONSE<<EOF' >> $GITHUB_ENV
|
|
curl https://httpbin.org/json >> $GITHUB_ENV
|
|
echo 'EOF' >> $GITHUB_ENV
|
|
```
|
|
|
|
### Adding a system path
|
|
|
|
`echo "{path}" >> $GITHUB_PATH`
|
|
|
|
Prepends a directory to the system `PATH` variable and makes it available to all subsequent actions in the current job; the currently running action cannot access the updated path variable. To see the currently defined paths for your job, you can use `echo "$PATH"` in a step or an action.
|
|
|
|
#### Example
|
|
|
|
This example demonstrates how to add the user `$HOME/.local/bin` directory to `PATH`:
|
|
|
|
``` bash
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
```
|
|
{% endif %}
|