Jenkins powershell plugin always builds successfully

前端 未结 6 1667
攒了一身酷
攒了一身酷 2021-02-04 00:46

I\'m using Jenkins PowerShell plugin to build a project.

However, I found that Jenkins always considers my build successful no matter what I type inside Windows P

6条回答
  •  你的背包
    2021-02-04 01:34

    I want to add here that I just ran into a quirk: you must have the powershell script end with exit and not return.

    My jenkins pipe looked like:

    script {
      result = powershell(returnStatus: true, script: '''...if(error condition) { return 1 }''')
    
      if(result) { error }
    }
    

    I was using if(error condition) { return 1 } and while the 1 was showing up as the return value in the jenkins console, it was not failing the build. When i used if(error condition) { exit 1 }, the build failed as expected.

    I think this is a helpful addition to this thread - the need to use exit and not return. But I don't understand this part: the pipe is checking for result to be non-zero. What is the difference between exit and return in a powershell directive that makes if(result) { error } not work as expected when using return?

提交回复
热议问题