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

Actions: Add examples for shells other than Bash #2121

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content/actions/reference/encrypted-secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ steps:
```
{% endraw %}

#### Example using PowerShell
#### Example using PowerShell Core

{% raw %}
```yaml
Expand All @@ -136,7 +136,7 @@ steps:
```
{% endraw %}

#### Example using Cmd.exe
#### Example using Windows `cmd`

{% raw %}
```yaml
Expand Down
83 changes: 65 additions & 18 deletions content/actions/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,57 @@ versions:

To set custom environment variables, you need to specify the variables in the workflow file. You can define environment variables for a step, job, or entire workflow using the [`jobs.<job_id>.steps.env`](/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsenv), [`jobs.<job_id>.env`](/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idenv), and [`env`](/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#env) keywords. For more information, see "[Workflow syntax for {% data variables.product.prodname_dotcom %}](/articles/workflow-syntax-for-github-actions/#jobsjob_idstepsenv)."

#### Example printing environment variables using Bash

```yaml
steps:
- name: Hello world
run: echo Hello world $FIRST_NAME $middle_name $Last_Name!
shell: bash
env:
FIRST_NAME: Mona
middle_name: The
Last_Name: Octocat
```

#### Example printing environment variables using PowerShell Core

```yaml
steps:
- name: Hello world
run: echo "Hello world $Env:FIRST_NAME $Env:middle_name $Env:Last_Name!"
shell: pwsh
env:
FIRST_NAME: Mona
middle_name: The
Last_Name: Octocat
```

#### Example printing environment variables using Windows `cmd`

```yaml
steps:
- name: Hello world
run: echo Hello world %FIRST_NAME% %middle_name% %Last_Name%!
shell: cmd
env:
FIRST_NAME: Mona
middle_name: The
Last_Name: Octocat
```

#### Example printing environment variables using Python

```yaml
steps:
- name: Hello world
run: |
import os
first_name = os.environ.get("FIRST_NAME", "")
middle_name = os.environ.get("middle_name", "")
last_name = os.environ.get("Last_Name", "")
print(f"Hello world {first_name} {middle_name} {last_name}!")
shell: python
env:
FIRST_NAME: Mona
middle_name: The
Expand All @@ -38,24 +85,24 @@ We strongly recommend that actions use environment variables to access the files

| Environment variable | Description |
| ---------------------|------------ |
| `CI` | Always set to `true`. |
| `GITHUB_WORKFLOW` | The name of the workflow. |
| `GITHUB_RUN_ID` | {% data reusables.github-actions.run_id_description %} |
| `GITHUB_RUN_NUMBER` | {% data reusables.github-actions.run_number_description %} |
| `GITHUB_ACTION` | The unique identifier (`id`) of the action. |
| `GITHUB_ACTIONS` | Always set to `true` when {% data variables.product.prodname_actions %} is running the workflow. You can use this variable to differentiate when tests are being run locally or by {% data variables.product.prodname_actions %}.
| `GITHUB_ACTOR` | The name of the person or app that initiated the workflow. For example, `octocat`. |
| `GITHUB_REPOSITORY` | The owner and repository name. For example, `octocat/Hello-World`. |
| `GITHUB_EVENT_NAME` | The name of the webhook event that triggered the workflow. |
| `GITHUB_EVENT_PATH` | The path of the file with the complete webhook event payload. For example, `/github/workflow/event.json`. |
| `GITHUB_WORKSPACE` | The {% data variables.product.prodname_dotcom %} workspace directory path. The workspace directory is a copy of your repository if your workflow uses the [actions/checkout](https://github.com/actions/checkout) action. If you don't use the `actions/checkout` action, the directory will be empty. For example, `/home/runner/work/my-repo-name/my-repo-name`. |
| `GITHUB_SHA` | The commit SHA that triggered the workflow. For example, `ffac537e6cbbf934b08745a378932722df287a53`. |
| `GITHUB_REF` | The branch or tag ref that triggered the workflow. For example, `refs/heads/feature-branch-1`. If neither a branch or tag is available for the event type, the variable will not exist. |
| `GITHUB_HEAD_REF` | Only set for pull request events. The name of the head branch.
| `GITHUB_BASE_REF` | Only set for pull request events. The name of the base branch.
| `GITHUB_SERVER_URL`| Returns the URL of the {% data variables.product.product_name %} server. For example: `https://{% data variables.product.product_url %}`.
| `GITHUB_API_URL` | Returns the API URL. For example: `{% data variables.product.api_url_code %}`.
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example: `{% data variables.product.graphql_url_code %}`.
| `CI` | Always set to `true`. |
| `GITHUB_WORKFLOW` | The name of the workflow. |
| `GITHUB_RUN_ID` | {% data reusables.github-actions.run_id_description %} |
| `GITHUB_RUN_NUMBER` | {% data reusables.github-actions.run_number_description %} |
| `GITHUB_ACTION` | The unique identifier (`id`) of the action. |
| `GITHUB_ACTIONS` | Always set to `true` when {% data variables.product.prodname_actions %} is running the workflow. You can use this variable to differentiate when tests are being run locally or by {% data variables.product.prodname_actions %}. |
| `GITHUB_ACTOR` | The name of the person or app that initiated the workflow. For example, `octocat`. |
| `GITHUB_REPOSITORY` | The owner and repository name. For example, `octocat/Hello-World`. |
| `GITHUB_EVENT_NAME` | The name of the webhook event that triggered the workflow. |
| `GITHUB_EVENT_PATH` | The path of the file with the complete webhook event payload. For example, `/github/workflow/event.json`. |
| `GITHUB_WORKSPACE` | The {% data variables.product.prodname_dotcom %} workspace directory path. The workspace directory is a copy of your repository if your workflow uses the [actions/checkout](https://github.com/actions/checkout) action. If you don't use the `actions/checkout` action, the directory will be empty. For example, `/home/runner/work/my-repo-name/my-repo-name`. |
| `GITHUB_SHA` | The commit SHA that triggered the workflow. For example, `ffac537e6cbbf934b08745a378932722df287a53`. |
| `GITHUB_REF` | The branch or tag ref that triggered the workflow. For example, `refs/heads/feature-branch-1`. If neither a branch or tag is available for the event type, the variable will not exist. |
| `GITHUB_HEAD_REF` | Only set for pull request events. The name of the head branch. |
| `GITHUB_BASE_REF` | Only set for pull request events. The name of the base branch. |
| `GITHUB_SERVER_URL` | Returns the URL of the {% data variables.product.product_name %} server. For example: `https://{% data variables.product.product_url %}`. |
| `GITHUB_API_URL` | Returns the API URL. For example: `{% data variables.product.api_url_code %}`. |
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example: `{% data variables.product.graphql_url_code %}`. |

### Naming conventions for environment variables

Expand Down
Loading