Jenkins 2 How to use PowerShell and custom build fail (specified exit code)

Jenkins addition to being used as a CI (continuous integration) tools, can also be used with other plugin for other reasons (egIIS restart, file compression backup ...), today take a look at how you can integrate with the PowerShell PowerShell command execution

Article Outline

  1. Install PowerShell plugin
  2. Setting Powershell plugin
  3. PowerShell 丟出 build fail

1. Install PowerShell plugin

  1. Manage Jenkins –> Manage Plugins

    1plugins

  2. Available –> Filter

    2install

2. Setting Powershell plugin

  1. Build –> ADD BUILD STEP –> Windows PowerShell

    3powershellsetting

  2. Command

    Direct write Powershell Syntax

    Big Box   Jenkins 2 How to use PowerShell and custom build fail (designated code Exit) sercontent.com/assets/3851540/22322570/e4af87d6-e3d7-11e6-9451-a82bd90e3358.png "alt =" 4commnad "/>

3. PowerShell 丟出 build fail

By default Jenkins as long as the implementation of PowerShell, whether or not executed correctly are considered as having SUCCESS, so it is necessary to manually throw build fail

5alwayserror

  • Manual throws an error (using a try catch, for example)

    • The actual implementation of a command PowerShell try catch bag
    • catch section threw exit 1to notify the Jenkins throw build fail

      Try
      {
          Get-Content C:securestringa.txt  -ErrorAction Stop
      }
      Catch
      {
          write-output "get data fail!"
          exit 1
      }
      

      6error

Cankaoziliao

  1. PowerShell Plugin

Guess you like

Origin www.cnblogs.com/lijianming180/p/12032159.html