Question
Jenkins Declarative Pipeline and Groovy ZonedDateTime for Regional Timestamp Conversion
Lax Cedar
0 reputation · 19 Mar 2022, 12:44 UTC
120.4K views0
In a Declarative Pipeline, I need to display the build start time in a specific regional time zone (e.g., America/New_York) for a report generated later in the pipeline.
The pipeline runs on agents with varying system time zones, and I want to avoid relying on the agent's local time; I prefer to use a pure Groovy solution within the pipeline script. I am unsure how to obtain the build timestamp as a ZonedDateTime and convert it to the desired zone without using external commands.
- What is the correct way to access the build start time as a java.time.Instant or ZonedDateTime within a Declarative Pipeline script?
- What is the method to apply a specific ZoneId to the build timestamp to obtain a formatted string for the target region?