|
| 1 | +filter Add-Mask { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Mask a value in GitHub Actions |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is |
| 8 | + replaced with the * character. You can use an environment variable or string for the mask's value. When you mask a value, |
| 9 | + it is treated as a secret and will be redacted on the runner. For example, after you mask a value, you won't be able to |
| 10 | + set that value as an output. |
| 11 | +
|
| 12 | + .EXAMPLE |
| 13 | + Add-Mask $SecretValue |
| 14 | +
|
| 15 | + Masks the value of $SecretValue so that its printed like ***. |
| 16 | +
|
| 17 | + .EXAMPLE |
| 18 | + $SecretValue1, $SecretValue2 | Mask |
| 19 | +
|
| 20 | + Masks the value of $SecretValue1 and $SecretValue2 so that its printed like ***, using the pipeline |
| 21 | +
|
| 22 | + .NOTES |
| 23 | + [Masking a value in a log | GitHub Docs](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#masking-a-value-in-a-log) |
| 24 | + #> |
| 25 | + [Alias('Mask')] |
| 26 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 27 | + 'PSAvoidLongLines', '', Scope = 'Function', |
| 28 | + Justification = 'Long documentation URL' |
| 29 | + )] |
| 30 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 31 | + 'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', |
| 32 | + Justification = 'Does not change state' |
| 33 | + )] |
| 34 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 35 | + 'PSAvoidUsingWriteHost', '', Scope = 'Function', |
| 36 | + Justification = 'Intended for logging in Github Runners which does support Write-Host' |
| 37 | + )] |
| 38 | + [CmdletBinding()] |
| 39 | + param( |
| 40 | + # The value to mask |
| 41 | + [Parameter( |
| 42 | + Mandatory, |
| 43 | + ValueFromPipeline |
| 44 | + )] |
| 45 | + [AllowNull()] |
| 46 | + [string[]] $Value |
| 47 | + ) |
| 48 | + |
| 49 | + foreach ($item in $Value) { |
| 50 | + Write-Host "::add-mask::$item" |
| 51 | + } |
| 52 | +} |
0 commit comments