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

Wrong timestamp retrieved from git ChangeSet

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Using the following groovy code:

      def thr = Thread.currentThread();
      def currentBuild = thr?.executable;
      def changes = currentBuild.getChangeSet();
      changes.getItems().each {
      	ChangeLogSet.Entry lastChange = (ChangeLogSet.Entry)it;
          lastChange.getTimestamp();
      }
      

      Produces a wrong timestamp (0).
      Reverting to git plugin 2.0.1 fixes the issue.

        Attachments

          Issue Links

            Activity

            Hide
            addictvim Dmitry Skorbovenko added a comment -

            Hi, I have checked code. the issue is in GitChangeSet:isoDateFormat method. git tool returns the time in seconds but java Date class requires milliseconds - so just multiply time by 1000
            fix:

                /** Convert to iso date format if required */
                private String isoDateFormat(String s) {
                    if (s.length() == 25 /* already in ISO 8601 */) return s;
            
                    // legacy mode
                    int i = s.indexOf(' ');
                    long time = Long.parseLong(s.substring(0,i));
                    return FastDateFormat.getInstance(ISO_8601).format(new Date(time * 1000)) + s.substring(i);
                }
            
            Show
            addictvim Dmitry Skorbovenko added a comment - Hi, I have checked code. the issue is in GitChangeSet:isoDateFormat method. git tool returns the time in seconds but java Date class requires milliseconds - so just multiply time by 1000 fix: /** Convert to iso date format if required */ private String isoDateFormat( String s) { if (s.length() == 25 /* already in ISO 8601 */ ) return s; // legacy mode int i = s.indexOf( ' ' ); long time = Long .parseLong(s.substring(0,i)); return FastDateFormat.getInstance(ISO_8601).format( new Date(time * 1000)) + s.substring(i); }
            Hide
            addictvim Dmitry Skorbovenko added a comment -
            Show
            addictvim Dmitry Skorbovenko added a comment - I have just sent pull request https://github.com/jenkinsci/git-plugin/pull/242
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Dmitry Skorbovenko
            Path:
            src/main/java/hudson/plugins/git/GitChangeSet.java
            http://jenkins-ci.org/commit/git-plugin/1f9f31d91129a7cb168dadda266154ea3f4f31ef
            Log:
            [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Dmitry Skorbovenko Path: src/main/java/hudson/plugins/git/GitChangeSet.java http://jenkins-ci.org/commit/git-plugin/1f9f31d91129a7cb168dadda266154ea3f4f31ef Log: [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Dmitry Skorbovenko
            Path:
            src/main/java/hudson/plugins/git/GitChangeSet.java
            http://jenkins-ci.org/commit/git-plugin/1c37dd40df54c02a547843a3be0a06e280dc3552
            Log:
            [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Dmitry Skorbovenko Path: src/main/java/hudson/plugins/git/GitChangeSet.java http://jenkins-ci.org/commit/git-plugin/1c37dd40df54c02a547843a3be0a06e280dc3552 Log: [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Mark Waite
            Path:
            src/main/java/hudson/plugins/git/GitChangeSet.java
            http://jenkins-ci.org/commit/git-plugin/617d600a9571931d77ee2352ffe1f37bb77ba603
            Log:
            Merge pull request #242 from AddictVim/jenkins_23791

            [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp

            Compare: https://github.com/jenkinsci/git-plugin/compare/5721ddbd1f76...617d600a9571

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/hudson/plugins/git/GitChangeSet.java http://jenkins-ci.org/commit/git-plugin/617d600a9571931d77ee2352ffe1f37bb77ba603 Log: Merge pull request #242 from AddictVim/jenkins_23791 [FIXED JENKINS-23791] convert seconds to milliseconds for timestamp Compare: https://github.com/jenkinsci/git-plugin/compare/5721ddbd1f76...617d600a9571
            Hide
            markewaite Mark Waite added a comment -

            Fixed in git plugin 2.2.4

            Show
            markewaite Mark Waite added a comment - Fixed in git plugin 2.2.4

              People

              • Assignee:
                ndeloof Nicolas De Loof
                Reporter:
                mooshben Moosh Ben
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: