Jenkins管道基于批处理退出代码没有失败

时间:2017-11-15 12:13:24

标签: batch-file jenkins jenkins-pipeline

我在使用Jenkins管道时出现问题,该管道在被调用的批处理文件失败时没有失败。我检查了批处理文件,它返回一个非零状态代码,但不知怎的,这似乎没有考虑。你们中有人有我的暗示吗?

所需的管道

node {
  stage('1'){
    dir('_src') {
      bat 'call test.bat'
    }
  }
}

在cmd窗口中调用批处理会产生以下结果

>call test.bat
INFO: Started ...
ERROR
Press any key to continue . . . 
>echo %ERRORLEVEL%
2

我还使用以下管道进行测试

node {
  stage('1'){
    dir('_src') {
      bat '''call test.bat
      echo %ERRORLEVEL%'''
    }
  }
}

...使用此输出

C:\_src>call test.bat 
INFO: Started ...
ERROR
Press any key to continue . . . 
2

尽管如此,管道并没有失败。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

应该是:

node {
  stage('1'){
    dir('_src') {
      bat '''call test.bat
      exit %ERRORLEVEL%'''
    }
  }
}

答案 1 :(得分:0)

你只写一个回声,而不是实际的回退/退出。尝试在脚本中添加具体的Exit 0或案例Exit 2

相关问题