Jayakumari Arumugham
Jayakumari Arumugham

Reputation: 353

How to add timestamp to the actual build log file under "jobs" folder under Jenkins home directory?

I am using Jenkins to automate our build and release process.

While executing a job under Jenkins, timestamp is not shown in the console build log.

To add timestamp to console build log, I have downladed "Timestamper" plugin and enabled "Add timestamps to the Console Output" option in each of my jobs' configurations under Jenkins. Now the timestamp is appened to the console build log in Jenkins.

But when I checked the same build log file in the "jobs" folder under Jenkins home directory, the timestamp in not appeneded in the log file.

As this log file is attached with job build details while sending mail to stakeholders, it is inevitable to add timestamp in the log file.

Please check the below contents.

In Console Build Log

15:40:04 Started by user TEST
15:40:04 [EnvInject] - Loading node environment variables.
15:40:04 Building in workspace C:\jenkins\workspace
15:40:04 No emails were triggered.

In Actual Log File

Started by user TEST
[EnvInject] - Loading node environment variables.
Building in workspace C:\jenkins\workspace
No emails were triggered.

So, I have two questions

  1. How to enable "Add timestamps to the Console Output" option as one time process to all Jobs as I have more jobs in Jenkins?
  2. How to add timestamp to the actual build log file under "jobs" folder under Jenkins home directory?

Thanks in advance.

Upvotes: 4

Views: 3915

Answers (3)

Ashutosh Mittal
Ashutosh Mittal

Reputation: 11

Try adding timestamps using 'options' in your jenkinsfile under pipeline:

pipeline {
...
    options {
        timestamps()
    }
...
}

Upvotes: 1

RaamEE
RaamEE

Reputation: 3497

Timestamper provides an API to get the log with the timestamps.

You can use my answer to "How to read the contents of /timestamps file in jenkins manually " on how to get the log with timestamps to pull a copy of the log and save it as a text file.

In short:

Use this URL

http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/timestamps/?time=yyyy-MM-dd%20HH:mm:ss&appendLog

to get a plain text response

2020-03-19 13:16:47  Jenkins did something here
2020-03-19 13:16:47  and this is something else that happend
2020-03-19 13:16:47  This line shows some output
2020-03-19 13:16:47  etc.
2020-03-19 13:16:47  etc.
2020-03-19 13:16:47  ...
2020-03-19 13:16:47  ...
2020-03-19 13:16:47
2020-03-19 13:16:47

and save it to a file in the job's folder.

Upvotes: 6

ping mai
ping mai

Reputation: 1

i had the same question #2.

if your jenkins server requires authentication you would need ~/.wgetrc:

http-user=<user>
http-password=<your password>

wget -O - --auth-no-challenge "http://<Jenkins server URL>/job/<Job name>/<job#>/consoleFull" | sed -e 's@<span class="timestamp"><b>\(.*\)</b> </span>@\1 @' > logfile.with.timestamp

Upvotes: 0

Related Questions