问题描述
stages {
stage('Monitoring logs') {
steps {
script {
sh '! grep "wow" output.log
}
}
}
}
有人可以解释一下这部分代码的作用吗-> sh '! grep "wow" output.log'
,如果在{{中找到“哇”字符串,如果对执行或管道执行的状态有任何影响,会产生什么影响? 1}}?
我知道output.log
将在grep "wow" output.log
中搜索“哇”字符串,但是我不知道output.log
会做什么?
解决方法
-
grep "wow" output.log
如果output.log
包含wow
成功(退出0),否则失败(退出非0)。 -
!
negates the exit code(0变为1;非0变为0)。 -
Jenkins’
sh
function运行shell脚本并在非0退出代码上引发异常,这将使管道失败。 *
如果output.log
包含wow
,则错误地执行管道操作。
* 通过使用-e
选项。