Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-9693

maven.build.timestamp.format is not obeyed in maven builds

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • maven-plugin
    • None

      Since Maven 2.1 it is possible to control the format of the maven.build.timestamp property by setting the maven.build.timestamp.format property. This works correctly with mvn version 3.0.3:

      pom.xml
      <project xmlns="http://maven.apache.org/POM/4.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>invalid.example.test</groupId>
          <artifactId>test</artifactId>
          <version>1.0-SNAPSHOT</version>
          <packaging>jar</packaging>
          <properties>
              <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
              <build.timestamp>${maven.build.timestamp}</build.timestamp>
          </properties>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/filtered-resources</directory>
                      <filtering>true</filtering>
                  </resource>
              </resources>
          </build>
      </project>
      
      src/main/filtered-resources/test.properties
      Build-Timestamp: ${build.timestamp}
      
      target/classes/test.properties
      Build-Timestamp: 2011-05-15T18:56:20+1000
      

      but in Jenkins 1.411 the default timestamp format is used instead:

      target/classes/test.properties
      Build-Timestamp: 20110515-1857
      

          [JENKINS-9693] maven.build.timestamp.format is not obeyed in maven builds

          Dan C created issue -

          Dan C added a comment -

          Presumably related to JENKINS-8573, where it looks like the "fix" was to manually interpolate the maven.build.timestamp property in Jenkins, thereby skipping all of maven's usual handling for it.

          Dan C added a comment - Presumably related to JENKINS-8573 , where it looks like the "fix" was to manually interpolate the maven.build.timestamp property in Jenkins, thereby skipping all of maven's usual handling for it.
          Dan C made changes -
          Link New: This issue is related to JENKINS-8573 [ JENKINS-8573 ]

          Chris Romack added a comment -

          So if maven.build.timestamp.format is ignored, is there another way to specify a custom timestamp format? I am running maven 3.0.3, Jenkins 1.428 and it is still not honoring maven.build.timestamp.format. Thanks.

          Chris Romack added a comment - So if maven.build.timestamp.format is ignored, is there another way to specify a custom timestamp format? I am running maven 3.0.3, Jenkins 1.428 and it is still not honoring maven.build.timestamp.format. Thanks.

          Jason Chaffee added a comment - - edited

          I too, need to find a way to honor the timestamp format as the default breaks the build as I cannot have "-" in the format. Works fine in maven outside of jenkins though.

          Jason Chaffee added a comment - - edited I too, need to find a way to honor the timestamp format as the default breaks the build as I cannot have "-" in the format. Works fine in maven outside of jenkins though.

          patrick clancey added a comment - - edited

          I have the same problem as Jason, broken builds when building with Jenkins. Has anyone found a work-around?

          There is a work-around using a Groovy snippet here...
          http://stackoverflow.com/questions/802677/adding-the-current-date-with-maven2-filtering

          Whilst not being particularly elegant, at least my builds are now working, which is always a plus! So a thanks to romaintaz for this.

          patrick clancey added a comment - - edited I have the same problem as Jason, broken builds when building with Jenkins. Has anyone found a work-around? There is a work-around using a Groovy snippet here... http://stackoverflow.com/questions/802677/adding-the-current-date-with-maven2-filtering Whilst not being particularly elegant, at least my builds are now working, which is always a plus! So a thanks to romaintaz for this.

          Jason Chaffee added a comment -

          The most disturbing part of this is that the build(s) work differently in Jenkins then they do simply running on the command-line. Not a very good thing if you are trying to have consistent and reproducible builds.

          Jason Chaffee added a comment - The most disturbing part of this is that the build(s) work differently in Jenkins then they do simply running on the command-line. Not a very good thing if you are trying to have consistent and reproducible builds.

          Mathias Dam added a comment -

          I have to agree with Jason Chaffee. While it is mostly just annoying, it begs the question: If this doesn't work as a command line build using Maven, what else might be different?

          Mathias Dam added a comment - I have to agree with Jason Chaffee. While it is mostly just annoying, it begs the question: If this doesn't work as a command line build using Maven, what else might be different?

          allenservedio added a comment -

          I wound up creating this timestamp via the Codehaus Build Number plugin (http://mojo.codehaus.org/buildnumber-maven-plugin/create-timestamp-mojo.html). Here is the Maven config that I used (in my plugin dependency management):

                                <plugin>
                                  <groupId>org.codehaus.mojo</groupId>
                                  <artifactId>buildnumber-maven-plugin</artifactId>
                                  <version>1.0</version>
                                  <executions>
                                    <execution>
                                      <phase>generate-resources</phase>
                                      <goals>
                                        <goal>create-timestamp</goal>
                                      </goals>
                                    </execution>
                                  </executions>
                                  <configuration>
                                    <timestampFormat>yyyyMMddHHmmssSSS</timestampFormat>
                                    <timestampPropertyName>releaseTimestamp</timestampPropertyName>
                                  </configuration>
                                </plugin>
          

          Am I correct that the reason this was not fixed already is that the point in the maven lifecycle where the statically formatted timestamp is created, the pom file(s) have not been evaluated. As such, it does not have access to this property (maven.build.timestamp.format) and so does not know that the user has defined it? If that is true, is there something else that can be used in Jenkin's Maven integration that can get access to this property and use it correctly?

          Thanks!
          Allen

          allenservedio added a comment - I wound up creating this timestamp via the Codehaus Build Number plugin ( http://mojo.codehaus.org/buildnumber-maven-plugin/create-timestamp-mojo.html ). Here is the Maven config that I used (in my plugin dependency management): <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> buildnumber-maven-plugin </artifactId> <version> 1.0 </version> <executions> <execution> <phase> generate-resources </phase> <goals> <goal> create-timestamp </goal> </goals> </execution> </executions> <configuration> <timestampFormat> yyyyMMddHHmmssSSS </timestampFormat> <timestampPropertyName> releaseTimestamp </timestampPropertyName> </configuration> </plugin> Am I correct that the reason this was not fixed already is that the point in the maven lifecycle where the statically formatted timestamp is created, the pom file(s) have not been evaluated. As such, it does not have access to this property (maven.build.timestamp.format) and so does not know that the user has defined it? If that is true, is there something else that can be used in Jenkin's Maven integration that can get access to this property and use it correctly? Thanks! Allen

          Adam Rofer added a comment - - edited

          All of the above workarounds provide different timestamps in each module in a multi-module build. The only thing I managed to get working was the following code:

          <plugin>
              <groupId>com.github.goldin</groupId>
              <artifactId>timestamp-maven-plugin</artifactId>
              <executions>
                  <execution>
                      <id>set-specific-timestamp</id>
                      <goals>
                          <goal>timestamp</goal>
                      </goals>
                      <phase>initialize</phase>
                      <configuration>
                          <time>{{ 
                                   def newdate = null;
                                   try {
                                       newdate = Date.parse( "${maven.build.timestamp.format}", "${maven.build.timestamp}");
                                   } catch (java.text.ParseException e) {
                                       newdate = Date.parse( "yyyyMMdd-HHmm", "${maven.build.timestamp}");
                                       println "THANKS JENKINS, FOR JENKINS-9693";
                                   }
                                   newdate 
                           }}</time>
                          <timestamp>
                              <property>actual-timestamp</property>
                              <pattern>${maven.build.timestamp.format}</pattern>
                          </timestamp>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          

          ...and then use actual-timestamp as your timestamp property.
          This assumes you already have maven.build.timestamp.format set as a property.

          Note that you can put whatever pattern you want in the <pattern> field, in this case it just formats it the way you originally wanted it

          Also note that this will only reach minute resolution on Jenkins builds since that's what Jenkins munges it to.

          Adam Rofer added a comment - - edited All of the above workarounds provide different timestamps in each module in a multi-module build. The only thing I managed to get working was the following code: <plugin> <groupId>com.github.goldin</groupId> <artifactId>timestamp-maven-plugin</artifactId> <executions> <execution> <id>set-specific-timestamp</id> <goals> <goal>timestamp</goal> </goals> <phase>initialize</phase> <configuration> <time>{{ def newdate = null; try { newdate = Date.parse( "${maven.build.timestamp.format}", "${maven.build.timestamp}"); } catch (java.text.ParseException e) { newdate = Date.parse( "yyyyMMdd-HHmm", "${maven.build.timestamp}"); println "THANKS JENKINS, FOR JENKINS-9693"; } newdate }}</time> <timestamp> <property>actual-timestamp</property> <pattern>${maven.build.timestamp.format}</pattern> </timestamp> </configuration> </execution> </executions> </plugin> ...and then use actual-timestamp as your timestamp property. This assumes you already have maven.build.timestamp.format set as a property. Note that you can put whatever pattern you want in the <pattern> field, in this case it just formats it the way you originally wanted it Also note that this will only reach minute resolution on Jenkins builds since that's what Jenkins munges it to.

            Unassigned Unassigned
            danc86 Dan C
            Votes:
            32 Vote for this issue
            Watchers:
            30 Start watching this issue

              Created:
              Updated:
              Resolved: