Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-3399

PowerShell module 2.x - capturing exit codes from scripts fail

    XMLWordPrintable

Details

    • Hide

      Using the call operator inside an "onlyif" will properly propagate an exit code from inside the called script.

      See test scenarios in description

      Show
      Using the call operator inside an "onlyif" will properly propagate an exit code from inside the called script. See test scenarios in description
    • 2
    • Windows 2016-08-10

    Description

      If I write the following powershell script:

      fail.ps1

      Exit 1
      

      and the following piece of Puppet code:

      test.pp

      exec { 'should not run':
        command  => 'Write-Host hello',
        onlyif   => '& C:\Users\Administrator\Desktop\fail.ps1',
        provider => 'powershell',
      }
      

      I would expect that my exec statement would not run because the onlyif returns an exit code of 1, but it does in fact run the command given. However if i do this:

      test.pp

      exec { 'should not run':
        command  => 'Write-Host hello',
        onlyif   => 'Exit 1',
        provider => 'powershell',
      }
      

      It works as expected (the exec does not get run)

      There must be something wrong with the way the exit codes are passed through. It is important to note that this was introduced in version 2.0.0 as per this support ticket: https://puppetlabs.zendesk.com/agent/tickets/18988

      Attachments

        Issue Links

          Activity

            People

              rob Rob Reynolds
              dylan.ratcliffe Dylan Ratcliffe
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support