[英]Jenkins capturing outputed messages
我有一个 Jenkins 管道,其中实现了一些阶段。 Jenkins 在作业运行时输出一些消息。
代码:
stage('My stage') {
options {
timeout(time: 2, unit: "MINUTES")
}
steps {
script {
./script.sh
}
}
}
}
Output:
...
20:12:40 Timeout set to expire in 2 min 0 sec
[Pipeline] {
[Pipeline] script
[Pipeline] {
20:12:40 ./script.sh '
20:14:40 Cancelling nested steps due to timeout
20:14:40 Sending interrupt signal to process
20:14:48 ...
20:14:48 + JOB_NAME=...
20:14:48 + BUILD_URL=...
20:14:48 + BUILD_ID=567
20:14:48 + BUILD_RESULT=SUCCESS
在此示例中,我正在处理一项工作,并且显示了很多消息。 我需要捕获此消息“由于超时而取消嵌套步骤”。 当 jenkins 输出此消息时,我希望能够向用户发送通知。
我不知道该怎么做。 你能帮我吗?
执行script.sh
后,您可以检查控制台日志,如下所示。
stage('My stage') {
options {
timeout(time: 2, unit: "MINUTES")
}
steps {
script {
sh "./script.sh"
// Checking the console log
def consoleLog = Jenkins.getInstance().getItemByFullName(env.JOB_NAME).getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER)).logFile.text
if(consoleLog.contains("Cancelling nested steps due to timeout")) {
echo "Send the Notification"
}
}
}
}
}
此外,如果您不想按顺序执行此操作,您可以创建一个并行阶段并继续检查日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.