In a Project
In a Project: The Scripts Every Project Has, Calling Other Programs, Secrets Out of Scripts.
Updated
- The Scripts Every Project Has (Journeyman): A build.ps1 gathers a project's chores in one script, each task a function that -Task picks through a ValidateSet parameter and a switch; Get-Command checks that the tools the project needs are installed, and $ErrorActionPreference = 'Stop' with throw stops the script at the first problem.
- Calling Other Programs (Journeyman): Programs such as git, dotnet and npm run from PowerShell by name, hand back their output as lines of text, take arguments from variables and arrays, and run by a path with & in front; a failing program doesn't stop a script by itself, so check $LASTEXITCODE after it, or set $PSNativeCommandUseErrorActionPreference to $true.
- Secrets Out of Scripts (Journeyman): A password or token written into a script travels wherever the script goes, so a script names the secret it needs and reads it from an environment variable, asks for it with Get-Credential, or fetches it from a SecretManagement vault, and stops with a clear message when it isn't there.