How to format timestamp of Jenkins xUnit results.xml? - jenkins

I am trying import test results from Jenkins to a third party PLM. And won't accept the timestamp:
timestamp="2022-08-28T18:52:53.915153"
How do I format timestamp in the results.xml in Jenkins before export such that the last six digits are omitted? I have job that runs every day to import the results, and so it would be a pain to manually format this timestamp every day.

Related

How to get apple's CF Absolute Time OR core data supported timestamp using terminal shell command?

date +"%s" - this command is giving output like: 1623847472
I want output like: 645540272 using shell command
I have tried date command's mostly all options but no success yet.
The date command doesn't have this option because it's not originally a macOS command line tool and uses a different reference date. It also doesn't support using alternate reference dates. You would need to adjust the value to make up the difference.
The date command uses the Unix time reference of January 1, 1970 UTC. Core Data and most other macOS and iOS frameworks use the Mac reference date of January 1, 2001 UTC. The difference between these reference dates is 978307200 seconds.
If you're using bash, you can get the number of seconds since the macOS reference date with
echo $((`date +"%s"` - 978307200))
That takes the Unix reference date, which %s prints, and subtracts the difference between the two reference dates to get the time since the macOS reference date.

Unable to jump to timestamp in Jenkins consoleFull log

I have timestamp plugin enabled in Jenkins. I am trying to jump to particular timestamp by using elapsed timestamp in URL, as http://localhost:8080/job/frog/11/consoleFull?elapsed=14:43:11
Is it possible to jump to timestamp in build log? or is there any error in url ?
Please help me on this.
You cannot jump to timestamps directly, but it is possible to skip an arbitrary amount of leading bytes. E.g., to skip the first million characters, you'd use
http://localhost:8080/job/frog/11/logText/progressiveText?start=1000000

Running a server with LUA and I need to trigger a function at a specific time every day

So I'm running a LUA script that executes every minute, this is controlled by software and I can't control the timing of the execution. I would like to check the time every day and trigger a function at a specific time. However, I would like to execute another script 5 minutes before that happens.
Right now I'm doing a string comparison using os.date() and parsing it to a string. It works, but the code isn't pretty and if the time changes, i have to manually change the time in two different variables, I'm pretty new to LUA so I've been having difficulty figuring out the best way to do this.
So the question is, how do I set a time variable, and compare that variable to os.date (or os.time) ?
There's no fancy way to do timers in pure Lua. What you can do to avoid os.date() strings, is to generate timestamps with preset dates, os.time accepts a key-value table to set a date:
timestamp = os.time({year=2019, month=1, day=n})
By iteratively increasing the n variable, you will receive a timestamp for every new n day after January 1st 2019. E.g.
os.date("%Y-%m-%d %H-%M-%S",os.time({year=2019,month=1,day=900})
--> 2021-06-18 12-00-00
If you can't save the day variable to keep track of (between application restarts), get the current "today" day and iterate from there:
os.date("%Y-%m-%d %H-%M-%S",
os.time({year=os.date("%Y"),month=os.date("%m"),day=os.date("%d")+n}
)
Using os.date with custom format and os.time makes your code independent of currently set date locale.
After you have determined the timestamp of the first task, offset the second actual task by five minutes secondTaskTimestamp = fistTaskTimestamp + 5*60 (or use os.time again). Your timer checker only should compare timestamps by now.
Now when you have to change the pre-configured time, you will only have to change the time-date of the first task, and the second task will be automatically offset.
Related: How do I execute a global function on a specific day at a specific time in Lua?

New Yahoo Finance URL

Since the previous Yahoo Finance download URL is not working anymore, I are now left with something like this:
https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1492524105&period2=1495116105&interval=1d&events=history&crumb=tO1hNZoUQeQ
Does anybody know how the period1 (and period2) translate into a date (and viceversa)
Any help appreciated!
Thanks!
It looks like they are just unix time stamps, or the seconds from the Epoch. Here is a website that can covert the information for you: http://www.unixtimestamp.com
This is oriented at recreating (kinda) the old functionality. I am running Fedora with Chrome.
(1) Figure out your user agent string for your web browser (I googled something like "what's my user agent string" and quickly found a page that would print it out for the browser you are using). It will be something like "Mozilla/5.0 (X11; Linux x86_64) ..."
(2) Install a package that will export a "cookies.txt" file for Chrome (also googled for something like "Chrome export cookies.txt" and quickly found a chrome extension that would export a cookies.txt for a page you are viewing).
(3) Go to the historical downloads page for a symbol of interest at Yahoo finance. Save the "crumb" in the download link (like you have above) and the cookies.txt for that page.
(4) Now you can use wget to get data. The command will be something like:
wget --load-cookies [THE COOKIES FILE YOU SAVED] -U "[THE USER AGENT STRING YOU FOUND]" -O [DESIRED OUTPUT CSV] https://query1.finance.yahoo.com/v7/finance/download/[THE SYMBOL YOU WANT HISTORICAL DATA FOR]?period1=[UNIX START TIME]\&period2=[UNIX END TIME]\&interval=1d\&events=history\&crumb=[THE CRUMB YOU SAVED]
The period1=... is the UNIX timestamp (seconds since 1970-Jan-1 00:00:00 GMT) of the start date and period2=... is the UNIX timestamp of the end date.
I was able to programmatically download a number of symbols this way. The column ordering of the resulting CSV file had changed from the old ichart API and the number of errors I found in the historical data was noticeably higher than the already quite high error rate in the data.
No guess on how long this will work or if it is stable over a long period of time. YMMV.
They are unix timestamps, or seconds since Epoch.
Quote taken from http://www.unixtimestamp.com/
What is the unix time stamp?
The unix time stamp is a way to track
time as a running total of seconds. This count starts at the Unix
Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is
merely the number of seconds between a particular date and the Unix
Epoch. It should also be pointed out (thanks to the comments from
visitors to this site) that this point in time technically does not
change no matter where you are located on the globe. This is very
useful to computer systems for tracking and sorting dated information
in dynamic and distributed applications both online and client side
The following C# code helps to convert between DateTime to Unix Timestamp
//credits to ScottCher
//reference http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa
private static DateTime UnixTimestampToDateTime(double unixTimeStamp)
{
//Unix timestamp Is seconds past epoch
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTimeStamp).ToLocalTime();
}
//credits to Dmitry Fedorkov
//reference http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa
private static double DateTimeToUnixTimestamp(DateTime dateTime)
{
//Unix timestamp Is seconds past epoch
return (dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
NOTE: make sure you round it up to zero decimal before substituting into period1 and period2
The period1 and period2 are just timestamps (POSIX timestamps). I think you can use any time of the date that you want to use. For example, for 2014-05-20, you can use any time from 00:00:00 to 23:59:59. (Update: Yahoo has just made a change here. You have to use a time that is after market close time, otherwise the data will miss the last day. I think 18:00:00 is working fine.)
I have put together some quick Python3 code to use that new API. Please check out GitHub for source code yahoo_quote_download.

Can Jenkins schedule builds using different time zones?

In some versions of crontab you can set the time zone for when the job should run like:
TZ=GMT
30 11 * * *
This would run at 11:30am GMT every day, even if the server was in some other time zone.
Even though Jenkins scheduling is based on cron, it doesn't seem to have this specific syntax. Is there some other way to do this in Jenkins?
Thanks
As Michael mentioned in his answer, this functionality was added. Here's an example:
TZ=Europe/Kiev
0 1 * * 5
That would run at 1:00 AM Ukraine time, once a week on Friday.
To get the names of time zones to use, you can use the column marked "TZ database name" in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Looks like they added this in 2.60.2.
There's no way to do this in Jenkins. You could trigger the builds by calling a URL from cron though.
Edit: This has since been added; see the other answers.

Resources