Jenkins 在从节点中构建日志

问题描述 投票:0回答:1

我正在尝试将我们的 jenkins 构建日志推送到 S3。 我在构建阶段使用了 Groovy 插件和以下脚本

// 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)

然后我使用S3插件将.txt文件推送到S3。

但是这个脚本从主节点获取构建日志文件。 构建日志如何从从节点传输到主节点? 我可以在没有主节点参与的情况下访问从节点上的构建日志文件吗?

从节点在某处构建时必须保留构建日志?我好像找不到。

jenkins jenkins-plugins jenkins-groovy jenkins-agent
1个回答
1
投票

我对 Groovy 不太熟悉,但这里是使用 shell 脚本对我有用的解决方案。 我正在使用 Jenkins 的“节点和标签参数插件”在从节点上运行我们的 java 进程。使用“构建 >> 执行 Shell”选项触发作业。日志被收集到一个文件中,如下所示:

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

此日志文件随后被推送到 S3 :

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

它对我们来说非常有效。希望对你也有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.