[英]How can I get the contents of a Jenkins job's Build Log in "Post-Build Actions"?
I have a Jenkins version 2.375.1 that runs a particular job.我有一个运行特定作业的 Jenkins 版本 2.375.1。
During the "Build Steps" portion of the job, a URL is printed to the execution console (build log).在作业的“构建步骤”部分,URL 被打印到执行控制台(构建日志)。 I am trying to pull that URL from the build log in order to add the URL to my post-build emails (Editable Email Notification).
我试图从构建日志中提取 URL,以便将 URL 添加到我的构建后电子邮件中(可编辑的 Email 通知)。
How can I get the contents of the Build Log at this point?此时如何获取Build Log的内容呢?
Here is a complete example to extract a string using regex in your post steps.这是一个在您的发布步骤中使用正则表达式提取字符串的完整示例。
pipeline {
agent any
stages {
stage('Build') {
steps {
echo "something else"
echo 'my_url="https://google.com"'
echo "something else"
}
post {
success {
script {
def consoleLog = Jenkins.getInstance().getItemByFullName(env.JOB_NAME).getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER)).logFile.text
// THis would extract "123456" from the console output my_url="1234567"
def url = (consoleLog =~ 'my_url="(.*)"')[0][1]
echo "URL is: $url"
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.