Upgrade to Pro — share decks privately, control downloads, hide ads and more …

psake - Good for more than just sushi

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

Glenn

July 25, 2016
Tweet

More Decks by Glenn

Other Decks in Technology

Transcript

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

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

    / Demo • Real world usage; Chocolatey packages for Neo4j
  3. In the case of a PowerShell scripts; • Check the

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

    • PowerShell Modules • Remoting • … anything you need ...
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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!
  10. -------------------------------------------------------------- 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
  11. • Create a new directory for our workshop md C:\Workshop

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

    task dependencies? • What would be a suitable default? Step 3 – Think…
  13. 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…
  14. 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…
  15. • Lint task • Test task • Package task •

    Package -> Deploy task • Default: Lint -> Test Step 3 – Think…
  16. 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" }
  17. ... Task Deploy -Description 'Deploy to the Gallery' ` -Depends

    Package { Write-Host "Deploy the package" }
  18. 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…
  19. 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…
  20. Invoke-Psake -properties @{"Version"="1.0"} Runs the build script and passes in

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

    'Package the module' { Write-Host "Package the module" Write-Host "Package version $Version" } Step 8 – Passing parameters