cake-build / cake-build/resources
Allow script parameters to be overridden by environment vars
- Dominant language
- PowerShell
- Stars
- 57
- Forks
- 72
- PR merge metrics
- No merged PRs in 30d
Description
I have a customised build.ps1 that allows certain script parameters to be overridden by environment variables, this is particularly useful for the `-Verbosity` parameter.
``` powershell
[CmdletBinding()]
Param(
[string]$Script = $(if (Test-Path env:/CAKE_SCRIPT) { "$env:CAKE_SCRIPT" } else { "build.cake" }),
[string]$Target = $(if (Test-Path env:/CAKE_TARGET) { "$env:CAKE_TARGET" } else { "Default" }),
[string]$Configuration = $(if (Test-Path env:/CONFIGURATION) { "$env:CONFIGURATION" } else { "Release" }),
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = $(if (Test-Path env:/CAKE_VERBOSITY) { "$env:CAKE_VERBOSITY" } else { "Verbose" }),
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
```
I am by no means a "powershell guy" but thought that this sort of alteration would be beneficial to others.
### Environment Variable Naming
**CAKE_SCRIPT**, **CAKE_TARGET** and **CAKE_VERBOSITY** are named to prevent potential conflicts with other environment variables, while **CONFIGURATION** is specifically named this way as AppVeyor (maybe other CI servers) will set this to the build configuration.
Of course I have only done this for the powershell bootstrapper as we are building on Windows, I assume a similar approach can be done for the .sh script.
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the repository's build.ps1 bootstrapper and the corresponding .sh script mentioned in the issue. Check how script parameters are currently defined, then verify that CAKE_SCRIPT, CAKE_TARGET, CAKE_VERBOSITY, and CONFIGURATION can override their defaults; confirm whether equivalent shell-script support is in scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, shell
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100