psake - Good for more than just sushi

Aac3dafaab7a7c2063d2526ba5936305?s=47 Glenn
July 25, 2016

psake - Good for more than just sushi

In this talk, Glenn will talk to us about PSake which is a build automation tool in PowerShell, inspired by Rake and Bake. Glenn will show how he converted from batch scripts to Psake for an open source packaging project he maintains. This will also include a small self paced workshop to create a PSake build script.

Created - 25th Jul 2016
Updated - 14th Dec 2016

Aac3dafaab7a7c2063d2526ba5936305?s=128

Glenn

July 25, 2016
Tweet

Transcript

  1. PSAKE Good for more than just sushi…. @glennsarti

  2. I was here e

  3. Me • Senior Software Engineer at Puppet Specialising in Windows

    • 15 years in Desktop Engineering and IT Navy, Government, Mining, Finance, Corporate • DevOps advocate
  4. What will we cover? • Introduction to psake • Workshop

    / Demo • Real world usage; Chocolatey packages for Neo4j
  5. (*) Disclaimer

  6. What is psake?

  7. “psake is a build automation tool written in PowerShell” psake

    github readme
  8. Like… cake bake grunt gogo gulp make rake etc.

  9. In the case of a PowerShell scripts; • Check the

    syntax and formatting • Run tests • Create a Package • Deploy to the PS Gallery
  10. Remember, it’s just PowerShell; • Access to the .Net Framework

    • PowerShell Modules • Remoting • … anything you need ...
  11. So if it’s just PowerShell why don’t I just use

    PowerShell then?
  12. Abstracts common automated tasks into an easy to use and

    easy to discover format
  13. Example Discovery and Usage

  14. PS> invoke-psake -docs

  15. PS> invoke-psake -docs psake version 4.6.0 Copyright (c) 2010-2014 James

    Kovacs & Contributors Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Clean Cleans the build Lint True Check scripts for Package Clean Package the Publish Publish a package PullRequest Lint, Test, Package Runs all checks Test True Runs unit tests
  16. PS> invoke-psake -docs psake version 4.6.0 Copyright (c) 2010-2014 James

    Kovacs & Contributors Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Clean Cleans the build Lint True Check scripts for Package Clean Package the Publish Publish a package PullRequest Lint, Test, Package Runs all checks Test True Runs unit tests
  17. PS> invoke-psake -docs psake version 4.6.0 Copyright (c) 2010-2014 James

    Kovacs & Contributors Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Clean Cleans the build Lint True Check scripts for Package Clean Package the Publish Publish a package PullRequest Lint, Test, Package Runs all checks Test True Runs unit tests
  18. PS> invoke-psake -docs psake version 4.6.0 Copyright (c) 2010-2014 James

    Kovacs & Contributors Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Clean Cleans the build Lint True Check scripts for Package Clean Package the Publish Publish a package PullRequest Lint, Test, Package Runs all checks Test True Runs unit tests
  19. PS> invoke-psake PullRequest

  20. PS> invoke-psake PullRequest psake version 4.6.0 Copyright (c) 2010-2014 James

    Kovacs & Contributors Executing Lint Task: Lint Executing Test Task: Test Executing Clean Task: Clean Executing Package Task: Package Build Succeeded!
  21. -------------------------------------------------------------- Build Time Report -------------------------------------------------------------- Name Duration ---- -------- Lint

    00:00:00.0066064 Test 00:00:00.0050065 Clean 00:00:00.0094264 Package 00:00:00.0093422 PullRequest 00:00:00 Total: 00:00:00.0413396
  22. Easy to discover and use

  23. None
  24. This workshop is for all PowerShell skill levels

  25. • https://github.com/psake/psake • The PowerShell Gallery Step 1 – Install

    psake
  26. • Create a new directory for our workshop md C:\Workshop

    • Create a new psake file C:\Workshop\default.ps1 Step 2 – Create default.ps1
  27. • What tasks will I have? • Can I use

    task dependencies? • What would be a suitable default? Step 3 – Think…
  28. As a PowerShell module developer I need to run PS

    Script Analyzer for linting and Pester for unit tests. I also need to package my module and then deploy it the Gallery. Step 3 – Think…
  29. As a PowerShell module developer I need to run PS

    Script Analyzer for linting and Pester for unit tests. I also need to package my module and then deploy it the Gallery. Step 3 – Think…
  30. • Lint task • Test task • Package task •

    Package -> Deploy task • Default: Lint -> Test Step 3 – Think…
  31. Task <taskname> -Description '<desc>'{ # Do something } Step 4

    – Write… Basic task definition…
  32. Task Lint -Description 'Check scripts for style' { Write-Host "Run

    PS Script Analyzer" } Task Test -Description 'Run unit tests' { Write-Host "Run Pester" } Task Package -Description 'Package the module' { Write-Host "Package the module" } Task Deploy -Description 'Deploy to the Gallery' { Write-Host "Deploy the package" }
  33. Task <taskname> -Depends <task>,<task> { # Do something } Step

    4 – Write… Dependencies…
  34. ... Task Deploy -Description 'Deploy to the Gallery' ` -Depends

    Package { Write-Host "Deploy the package" }
  35. PS> CD C:\Workshop PS> Invoke-Psake -docs Step 5 – Try

    it out…
  36. psake version 4.6.0 Copyright (c) 2010-2014 James Kovacs & Contributors

    Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Deploy Package Deploy to the Gallery Lint Check scripts for s… Package Package the module Test Run unit tests Step 5 – Try it out…
  37. Task Default -Depends <task>,<task> Step 6 – Add default task

    Default Task
  38. ... Task Default –Depend Lint,Test

  39. psake version 4.6.0 Copyright (c) 2010-2014 James Kovacs & Contributors

    Name Alias Depends On Default Description ---- ----- ---------- ------- ----------- Deploy Package Deploy to the Gallery Lint True Check scripts for s… Package Package the module Test True Run unit tests Step 7 – Try it out…
  40. PS> Invoke-Psake Lint PS> Invoke-Psake Deploy PS> Invoke-Psake PS> Invoke-Psake

    Lint,Test,Deploy Step 7 – Try it out…
  41. Invoke-Psake -properties @{"Version"="1.0"} Runs the build script and passes in

    parameter ‘Version’ with value ‘1.0’ Step 8 – Passing parameters
  42. properties { $Version = $null } ... Task Package -Description

    'Package the module' { Write-Host "Package the module" Write-Host "Package version $Version" } Step 8 – Passing parameters
  43. PS> Get-Help Invoke-Psake -full http://psake.readthedocs.io/en/latest/ Step 9 – More info

  44. What about psake in the real world?

  45. None
  46. Other examples…

  47. https://github.com/devblackops/PasswordState https://github.com/devblackops/InfoBlox https://github.com/devblackops/watchmen Brandon Olin

  48. A PowerShell Module Release Pipeline http://ramblingcookiemonster.github.io/PSDeploy-Inception/

  49. Example CI pipeline for DSC resources https://github.com/Xainey/DSCBasicPipeline

  50. Invoke-Build https://github.com/nightroman/Invoke-Build https://github.com/nightroman/Invoke-Build/wiki/Comparison-with-psake

  51. https://github.com/psake https://www.powershellgallery.com/packages/psake @GlennSarti http://glennsarti.github.io/ https://github.com/glennsarti/neo4j-community-chocolatey https://speakerdeck.com/glennsarti All images are copyright

    of their respective owners