在Jenkins中,如何将控制台输出结果存储到github?

xghobddn  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(275)

如何将测试报告部署回Github或我的本地?我使用webhook建立了从Github到Jenkins的连接,使用Jenkins设置/Pipeline建立了从Jenkins到Github的连接,并添加了我的仓库。
测试的结果显示在Jenkins/控制台输出中。如何将结果存储在其他地方(如GithUb)或我的本地或某个服务器上,是否有此设置?

  • 谢谢-谢谢
daupos2t

daupos2t1#

有很多方法可以做到这一点,但这里有一个方法。

pipeline {
    agent any
    stages {
        stage('Sample') {
            steps {
                script {
                    echo "Somehitng 1"
                    echo "Something 2"
                    // Read the console log
                    def consoleLog = Jenkins.getInstance().getItemByFullName(env.JOB_NAME).getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER)).logFile.text
                    //Write the log to a file
                    writeFile(file: "Log_${BUILD_NUMBER}.txt", text: consoleLog, encoding: "UTF-8")
                    sh'''
                        git add *
                        git commit -m "Add console log"
                        git push
                    '''
                }
            }
        }
    }
}

相关问题