DanT96
DanT96

Reputation: 3

Exporting Console Output of Jenkins Pipeline

I have built a pipeline which runs a set of sql scripts to generate results. I would like to be able to export the console output, ideally into a .txt file or .xlsx file. Is this possible? For info I drive the pipeline via GitHub.

Thanks

Tried searching the web but have been unable to find a solution

Upvotes: 0

Views: 706

Answers (1)

ycr
ycr

Reputation: 14604

Do you want to Save the Console output to a file and then Commit it to Github? Check the following sample Pipeline.

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
                    '''
                }
            }
        }
    }
}

Upvotes: 2

Related Questions