BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Simple Build Automation with psake

Simple Build Automation with psake

This item in japanese

psake is a build automation tool integrated with PowerShell (PS). Version 2.01 works with PowerShell 2.0. Ayende Rahien is using it to build Rhino Tools.

James Kovacs, the project owner, explains what is the improvement brought by psake:

It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge.

Beside making it compatible with PS 2.0, in version 2.01 psake has been rewritten as a PS module. The main benefits would be:

  1. Build scripts don't need to know where psake is installed, they just call Invoke-psake and it works.
  2. Encapsulation. Global variables are no longer required since they can be private to a module unless explicitly exported.
  3. Modules can be unloaded if needed which removes all the code and variables from memory.

Other enhancements in 2.01 are:

  1. Coding style is different.
  2. Try/Catch is used instead of the "Trap" statement.
  3. Got rid of the "exec" function.
  4. You can now define "Pre" and "Post" actions for a task.
  5. You can define how the task name will be formatted.
  6. You can define a "TaskSetup" function that will be executed before every task (took that from NUnit).
  7. You can define a "TaskTearDown" function that will be executed after every task (took that from NUnit too).
  8. Create a global variable called "psake_buildSucceeded" that will be set to true if the build succeeds - scripts can check this.
  9. Also added a "$noexit" switch to Run-Psake so that the function will not use the exit() function so that you can test a build script at the command line without PS closing down (the default behavior when the build fails is to call exit(1) so that the calling code can determine if the build failed or not).
  10. The psake-buildTester.ps1 had to be changed slightly in order for it to call the Invoke-psake function.
  11. Added more examples in the .\examples folder for POST conditions, PRE and POST Actions, etc.

Ayende Rahien wrote about using psake to build his Rhino Tools. The project initially used a NAnt-based built tool which turned out to be too complex, tending to create “zones of ‘there be dragons’, where only the initiated go, and even they go with trepidation.” After evaluating the possibility to use Rake or Bake, Rahien turned toward psake which did the job in 50 lines.

psake can be downloaded from GitHub under the MIT License.

Rate this Article

Adoption
Style

BT