Chris McKelt
Chris McKelt

Reputation: 1388

PSAKE powershell & execute task not running

Trying to get a PSAKE script to work. Its seems that tasks are not executing the functions within them?

I have 2 files

-- default.ps1 --
Import-Module "C:\dev\Phoenix\trunk\Build\BuildScripts\include.ps1"
Import-Module "C:\Software\PSAKE\JamesKovacs-psake-b0094de\psake.psm1"
Invoke-psake "C:\dev\Phoenix\trunk\Build\BuildScripts\build.ps1"
remove-module psake


-- build.ps1 --
$framework = '4.0'

properties {
    $root_dir = 'c:\dev\Phoenix\trunk\'
    $integration_deploy_dir = '\\Server025\Phoenix_IntegrationTests\'
    $build_scripts_dir = '$root_dir\Build\BuildScripts'
    $test_dir =  Join-Path $root_dir '\Tests\Core.UnitTests\bin\Debug'
    $dll = Join-Path $test_dir 'Phoenix.Core.UnitTests.dll'
} 


task default -depends Test

task MsBuild {  exec { msbuild /version }}

task Test -depends Deploy
{
    Write-Host "Start task Test"
Add-PSSnapIn Gallio
Write-Host "TEST --  $dll" 
Test-Gallio $test_dir Release x64 $dll "Core.UnitTests"     ## FYI - call to include func
Write-Host "End task Test"
}

task Deploy
{
Write-Host "Start task deploy"
Write-Host "Deploying to integration server"
copy $root_dir"\Sites" $integration_deploy_dir -Recurse -Force
Write-Host "End task deploy"    
}

At the moment it just seems to 'print out' the stuff listed within tasks without actually doing anything. What am I missing? Thanks

Sorry forgot to mention I really just want to get the COPY method working first -- thx


Thanks for the help - Ive made all your suggestions and still no luck.

If I put the code 'inline' rather that in PSAKE tasks the code runs fine.

I now have this

-- default.ps1
Import-Module C:\dev\Phoenix\trunk\Build\BuildScripts\include.ps1
Import-Module C:\Software\PSAKE\JamesKovacs-psake-b0094de\psake.psm1
Invoke-psake C:\dev\Phoenix\trunk\Build\BuildScripts\build.ps1
remove-module psake

-- build.ps1 $framework = '4.0'

properties {
$root_dir = 'c:\dev\Phoenix\trunk'
$sites_dir = 'c:\dev\Phoenix\trunk\sites'
$integration_deploy_dir = '\\Vsydnweb025\Phoenix_IntegrationTests\'
$build_scripts_dir = "$root_dir\Build\BuildScripts"
}

task default -depends Deploy

task Deploy
{
Write-Host 'Start task deploy'
Write-Host 'Deploying to integration server'
copy $sites_dir $integration_deploy_dir -Recurse -Force
Write-Host 'End task deploy'
get-childitem $integration_deploy_dir -include *.svclog -recurse | foreach ($_)  {remove-item $_.fullname}
}

The output of this is as follows:

Write-Host 'Start task deploy'
Write-Host 'Deploying to integration server'
copy $sites_dir $integration_deploy_dir -Recurse -Force
Write-Host 'End task deploy'
get-childitem $integration_deploy_dir -include *.svclog -recurse | foreach ($_) {remove-item $_.fullname}


Build Succeeded!

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name   Duration        
----   --------        
Deploy 00:00:00.0006013
Total: 00:00:02.5335350

So it seems the functions within the task are just being printed out.

The copy function did not run - nor the Piped .SvcLog file delete

Ie on the screen I would expect

'Start task deploy'

instead of

Write-Host 'Start task deploy'

Ill keep trying to get it to work.

Thanks for your help!!!

Upvotes: 1

Views: 2166

Answers (2)

Chris McKelt
Chris McKelt

Reputation: 1388

Had this answered in the google group

The beginning "{" needs to be on the same line as the "task" function since it's a scriptblock that is being passed as a parameter to the "task" function. PS is interpreting your code as 2 statements instead of 1 statement.

Upvotes: 7

nimizen
nimizen

Reputation: 3419

I've not done anything with PSAKE but with regards to Powershell, the following needs 'fixing':

$root_dir = 'c:\dev\Phoenix\trunk\'

Remove the trailing '\' as when you concatenate this variable with other strings (which begin with '\') you will end up with a double '\'.

Also:

$build_scripts_dir = '$root_dir\Build\BuildScripts'

This should have double quotes to ensure the variable is expanded correctly:

$build_scripts_dir = "$root_dir\Build\BuildScripts"

Maybe correct these and see if you get any more meaningful errors?

I suspect you will also need to remove the double quotes from around your script/module calls:

Import-Module C:\dev\Phoenix\trunk\Build\BuildScripts\include.ps1
Import-Module C:\Software\PSAKE\JamesKovacs-psake-b0094de\psake.psm1
Invoke-psake C:\dev\Phoenix\trunk\Build\BuildScripts\build.ps1
remove-module psake

...and see here for a good run-down on how to call scripts from within scripts. The double quotes you're using turns the call into a string (which won't execute). If you need to use double quotes (i.e. your path includes spaces) then you need to preface the path with the call operator '&':

& "C:\dev\Phoenix\trunk\Build\BuildScripts\build.ps1"

Obviously, you don't need to do this as your path has no spaces.

Upvotes: 1

Related Questions