Fix race condition

Global variables were stored as a singleton which meant multiple builds
running at the same time could collide when the global variables
attempted to update

Clean up code

Update tests to use JenkinsRule