Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject command line arguments into psake

I would like to inject command line parameters into my psake build script like: .\build.ps1 Deploy environment="development"

But psake will treat every argument as a Task and will answer "task does not exists"

Is it possible to inject command line arguments in psake?

build.ps1 -->
Import-Module '.\psake.psm1'
Invoke-psake '.\tasks.ps1' $args
Remove-Module psake
like image 527
orjan Avatar asked Feb 05 '10 16:02

orjan


2 Answers

The latest release of psake now supports passing parameters to Invoke-psake, e.g.

Invoke-psake .\parameters.ps1 -parameters @{"p1"="v1";"p2"="v2"} 

This feature has just been added. :)

like image 68
James Allen Avatar answered Nov 18 '22 08:11

James Allen


A global variable will solve my problem for now and with only one reference to $global:arg_environent it will be easy to change if i find a better way to inject the properties.

build.ps1

param(
    [Parameter(Position=0,Mandatory=0)]
    [string]$task,
    [Parameter(Position=1,Mandatory=0)]
    [string]$environment = 'dev'
)

clear
$global:arg_environent = $environment
Import-Module .\psake.psm1 
Invoke-psake tasks.ps1 $task
Remove-Module psake

tasks.ps1

properties {
    $environment = $global:arg_environent
}

task default -depends Deploy

task Deploy {  
   echo "Copy stuff to $environment"
}
like image 31
orjan Avatar answered Nov 18 '22 07:11

orjan