2

I am trying to push our jenkins build logs to S3. I used Groovy plugin and the following script in Build phase

// This script should be run in a system groovy script build step.

// The FilePath class understands what node a path is on, not just the path.
import hudson.FilePath

// Get path to console log file on master.
logFile = build.getLogFile()

// Turn this into a FilePath object.
logFilePathOnMaster = new FilePath(logFile)

logFileName = build.envVars["JOB_BASE_NAME"] + build.envVars["RT_RELEASE_STAGING_VERSION"]  + '.txt'

// Create remote file path obj to build agent.
remoteLogFile = new FilePath(build.workspace, logFileName)

// Copy contents of master's console log to file on build agent.
remoteLogFile.copyFrom(logFilePathOnMaster)

And then I am using S3 plugin to push .txt files to S3.

But this script fetches the build log file from the master node. How are the build logs transferred from slave to master node ? Can I access the build log file on my slave node without master's involvement at all ?

The slave node must be preserving the build logs while building somewhere ? I cant seem to find it.

1 Answers1

1

I am not much familiar with Groovy but here is the solution which worked for me using shell script. I am using Jenkins 'Node and Label parameter plugin' to run our java process on a slave node. Job is triggered using 'Build >> Execute Shell' option. The log is collected into a file as below :

    sudo java  -jar xxx.jar | sudo tee -a ${JOB_NAME}/${BUILD_NUMBER}.log 2>&1

This log file is then pushed to S3 :

    sudo aws --region ap-south-1  s3  cp ${JOB_NAME}/${BUILD_NUMBER}.log  s3://bucket/JenkinsLogs/${JOB_NAME}/${BUILD_NUMBER}.log

Its working perfectly for us. Hope it helps you too.

Priya Nalang
  • 107
  • 1
  • 9