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

Allow script parameters to be overridden by environment vars #11

Open
Philo opened this issue Jul 29, 2016 · 0 comments
Open

Allow script parameters to be overridden by environment vars #11

Philo opened this issue Jul 29, 2016 · 0 comments

Comments

@Philo
Copy link

Philo commented Jul 29, 2016

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.

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant