Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Explicitly set MySQL service timezone in bitbucket-pipeline.yml?

Stew August 21, 2017

I have a timezone sensitive set of tests in my code-base (ruby). I make unit-test assertions about host and dbms timezone being locked to UTC. When making a connection to MySQL (using the ruby mysql2 adapter gen) I explicitly set connection options:

Mysql2::Client.default_query_options.merge!({:database_timezone=>:utc, :application_timezone=>:utc})

What this does is to ensure that the TZ model used by MySQL server is to ensure both MySQL and the adaper do NOT convert times based on assumptions about locale. This works fine in my development and production environments. 

As such my unit tests assert that in the context of a connection, I query back the TZ settings and ensure they're UTC (which in my case look this way):

Instantiated @ 2017-08-21 12:21:51 UTC Ver[5.7.19] Gl[+00:00] Sn[+00:00]

Where the Global (Gl) and Session (Sn) timezones returned by MySQL are '+00:00' which is how MySQL models UTC.

That is what should be working on Bitbucket Pipeline Mysql service integraiton too, but something is not working. The same assertion on startup within unit-tests provides the following variation:

Instantiated @ 2017-08-21 12:21:51 UTC Ver[5.7.19] Gl[SYSTEM] Sn[SYSTEM]

Now - to get this output, as I understand it - the client options I set are not being consumed/set by the MySQL service I'm integrating into my pipeline? Is there a way to enable this ? Or better - to explicitly set the MySQL service to UTC inherently within the configuration YML file? 

Many thanks for any suggestions/ideas. I'd really like to avoid putting in environmental conditionals into the tests - given this is very timezone sensitive. 

 

1 answer

0 votes
Stew August 22, 2017

OK, so on further digging - it appears the ruby client wrapper I'm using doesn't propagate the connection settings during the initialisation of the wrapper? So this leaves me wondering if I may have set TZ manually when experimenting on the commandline. So ruby aside....my question is now more simple. How can I state in my bitbucket-pipeline.yml config - where I define my mysql service, that I want the mysql server to operate in UTC.

The equivalent console commands are:

SET GLOBAL time_zone = '+00:00'


SET SESSION time_zone = '+00:00'

And this is what I woudl like to see when I query on startup:

SELECT @@global.time_zone, @@session.time_zone would return 2 results:

"+00:00", "+00:00"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events