问题
I am trying to read the /timestamps file that gets generated for the build but I am not able to understand the file format as when I try to open it is contains some special characters. I wanted to use this file for a script which will run as a batch command after the build has completed. Any help would be appreciated. Thanks
回答1:
It is considered bad practice to rely of the internal data-structure of a plugin like this.
Suggest you contact the writer of that plugin and see if he can give some API for that.
回答2:
If you're using the timestamper plugin https://plugins.jenkins.io/timestamper/
You can read the log using the plugin's API.
http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/console
will return the console view with the timestamps if the plugin is enabled or or without it if it's disabled.
http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/consoleText
will return the log as plain text
Timestamper Plugin API
But when the plugin is enabled for the job, you can use the API which is available here under the "Scripting" section. The response is a plain text format.
You can format the timestamp that is returned to be date, time, date + time, elapsed time (time since job started), etc.
examples
http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/timestamps/?time=yyyy-MM-dd%20HH:mm:ss&appendLog
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
returns the timestamp and appends the log. The date is formatted as "2020-03-19 16:30:23"
using M instead of MM will return the month without a preceding 0.
using MMM will return the month as a 3 letters month, e.g. "MAR"
http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/timestamps
2.667
2.670
2.768
32.778
32.778
32.820
Will return the timestamps without the log lines. Simple plain text list of the seconds since the build started.
http://${JENKINS_IP_PORT}/job/${JOB_NAME}/${JOB_NUMBER}/timestamps/?time=yyyy-MM-dd%20HH:mm:ss
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
2020-03-19 13:16:47
Will return a formatted list of timestamps
Warning
The Timestamper API is available only if a job enabled the plugin. Accessing the API url in other cases will return an empty response.
来源:https://stackoverflow.com/questions/16963410/how-to-read-the-contents-of-timestamps-file-in-jenkins-manually