簡體   English   中英

如何在“構建后操作”中獲取 Jenkins 作業的構建日志的內容?

[英]How can I get the contents of a Jenkins job's Build Log in "Post-Build Actions"?

我有一個運行特定作業的 Jenkins 版本 2.375.1。

在作業的“構建步驟”部分,URL 被打印到執行控制台(構建日志)。 我試圖從構建日志中提取 URL,以便將 URL 添加到我的構建后電子郵件中(可編輯的 Email 通知)。

此時如何獲取Build Log的內容呢?

這是一個在您的發布步驟中使用正則表達式提取字符串的完整示例。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM