Skip to content

Commit 06b5ead

Browse files
authored
Merge pull request github#26314 from github/repo-sync
repo sync
2 parents 4155b92 + 1f41f10 commit 06b5ead

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

content/actions/security-guides/encrypted-secrets.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ steps:
227227
```
228228
{% endraw %}
229229
230+
Secrets cannot be directly referenced in `if:` conditionals. Instead, consider setting secrets as job-level environment variables, then referencing the environment variables to conditionally run steps in the job. For more information, see "[Context availability](/actions/learn-github-actions/contexts#context-availability)" and [`jobs.<job_id>.steps[*].if`](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsif).
231+
232+
If a secret has not been set, the return value of an expression referencing the secret (such as {% raw %}`${{ secrets.SuperSecret }}`{% endraw %} in the example) will be an empty string.
233+
230234
Avoid passing secrets between processes from the command line, whenever possible. Command-line processes may be visible to other users (using the `ps` command) or captured by [security audit events](https://docs.microsoft.com/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing). To help protect secrets, consider using environment variables, `STDIN`, or other mechanisms supported by the target process.
231235
232236
If you must pass secrets within a command line, then enclose them within the proper quoting rules. Secrets often contain special characters that may unintentionally affect your shell. To escape these special characters, use quoting with your environment variables. For example:

content/actions/using-workflows/workflow-syntax-for-github-actions.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,31 @@ steps:
342342
uses: actions/[email protected]
343343
```
344344

345+
#### Example: Using secrets
346+
347+
Secrets cannot be directly referenced in `if:` conditionals. Instead, consider setting secrets as job-level environment variables, then referencing the environment variables to conditionally run steps in the job.
348+
349+
If a secret has not been set, the return value of an expression referencing the secret (such as {% raw %}`${{ secrets.SuperSecret }}`{% endraw %} in the example) will be an empty string.
350+
351+
{% raw %}
352+
```yaml
353+
name: Run a step if a secret has been set
354+
on: push
355+
jobs:
356+
my-jobname:
357+
runs-on: ubuntu-latest
358+
env:
359+
super_secret: ${{ secrets.SuperSecret }}
360+
steps:
361+
- if: ${{ env.super_secret != '' }}
362+
run: echo 'This step will only run if the secret has a value set.'
363+
- if: ${{ env.super_secret == '' }}
364+
run: echo 'This step will only run if the secret does not have a value set.'
365+
```
366+
{% endraw %}
367+
368+
For more information, see "[Context availability](/actions/learn-github-actions/contexts#context-availability)" and "[Encrypted secrets](/actions/security-guides/encrypted-secrets)."
369+
345370
### `jobs.<job_id>.steps[*].name`
346371

347372
A name for your step to display on {% data variables.product.prodname_dotcom %}.

0 commit comments

Comments
 (0)