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

Environment Variables BUILD_ID and BUILD_NUMBER now return the same value

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • core
    • None
    • Since version 1.597

      With this release jenkins changed the build identifier to the build number (instead of timestamp). Now the BUILD_NUMBER and BUILD_ID both return the build number and there is no way to get the timestamp from the environment variables.
      According to the documentation BUILD_ID should return the timestamp.

      BUILD_ID
      The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)

      Possible fixes:

      • Change BUILD_ID to return the timestamp
      • Add Env-Var BUILD_TIMESTAMP or similar

          [JENKINS-26520] Environment Variables BUILD_ID and BUILD_NUMBER now return the same value

          cojeff Read my comment from above. You can use the Zentimestamp plugin which will expose BUILD_TIMESTAMP environment variable.

          Steven Christou added a comment - cojeff Read my comment from above. You can use the Zentimestamp plugin which will expose BUILD_TIMESTAMP environment variable.

          If BUILD_TIMESTAMP is a Jenkins variable, why can't it be used directly (without using the Zentimestamp plugin).

          Malcolm Fernandes added a comment - If BUILD_TIMESTAMP is a Jenkins variable, why can't it be used directly (without using the Zentimestamp plugin).

          Daniel Beck added a comment -

          If BUILD_TIMESTAMP is a Jenkins variable, why can't it be used directly (without using the Zentimestamp plugin).

          That variable is not provided by Jenkins core. It's not defined without Zentimestamp.

          Jenkins core changed the storage format and therefore the format of the BUILD_ID variable contents. If you were using it for something other than a reference to the build folder name (e.g. to indicate start date and time of a build), you now need to switch to using BUILD_TIMESTAMP provided by Zentimestamp, or determine the date on your own (some solutions provided in comments above).

          The recent change in core was a documentation fix.

          Daniel Beck added a comment - If BUILD_TIMESTAMP is a Jenkins variable, why can't it be used directly (without using the Zentimestamp plugin). That variable is not provided by Jenkins core. It's not defined without Zentimestamp. Jenkins core changed the storage format and therefore the format of the BUILD_ID variable contents. If you were using it for something other than a reference to the build folder name (e.g. to indicate start date and time of a build), you now need to switch to using BUILD_TIMESTAMP provided by Zentimestamp, or determine the date on your own (some solutions provided in comments above). The recent change in core was a documentation fix.

          I have installed zentimestamp-plugin and trying to get build execution time in email notifications.
          I used Zentimestamp plugin and using env variable BUILD_TIMESTAMP using following ways but not able to get actual time stamp value

          ${BUILD_TIMESTAMP}
          $BUILD_TIMESTAMP
          BUILD_TIMESTAMP
          

          Somebody Please answer here ? http://stackoverflow.com/questions/29580315/jenkins-how-to-use-zentimestamp-plugin-to-get-build-execution-time

          Swapnil Kotwal added a comment - I have installed zentimestamp-plugin and trying to get build execution time in email notifications. I used Zentimestamp plugin and using env variable BUILD_TIMESTAMP using following ways but not able to get actual time stamp value ${BUILD_TIMESTAMP} $BUILD_TIMESTAMP BUILD_TIMESTAMP Somebody Please answer here ? http://stackoverflow.com/questions/29580315/jenkins-how-to-use-zentimestamp-plugin-to-get-build-execution-time

          Did you select 'Change date pattern for the BUILD_TIMESTAMP (build timestamp) variable' and supply a 'Date and Time Pattern'.

          I believe if you do not select that option, the variable does not get expanded.

          I set a value for 'Date and Time pattern as 'yyyy-MM-dd_HH-mm-ss' and it worked fine.

          Malcolm Fernandes added a comment - Did you select 'Change date pattern for the BUILD_TIMESTAMP (build timestamp) variable' and supply a 'Date and Time Pattern'. I believe if you do not select that option, the variable does not get expanded. I set a value for 'Date and Time pattern as 'yyyy-MM-dd_HH-mm-ss' and it worked fine.

          That's right. The actual behavior of the Zen-Timestamp plugin is to modify the environment variable only if "Change date pattern" was checked. With older Jenkins versions, the variable BUILD_ID was
          already set to the default format by the Jenkins core and was only modified by the plugin if this option was checked and a different format was selected. The new Zen plugin must be fixed to set the BUILD_TIMESTAMP variable in any case, even if there was no format defined inside the job or node configuration. I will file a ticket for this issue.

          Michael Rentschler added a comment - That's right. The actual behavior of the Zen-Timestamp plugin is to modify the environment variable only if "Change date pattern" was checked. With older Jenkins versions, the variable BUILD_ID was already set to the default format by the Jenkins core and was only modified by the plugin if this option was checked and a different format was selected. The new Zen plugin must be fixed to set the BUILD_TIMESTAMP variable in any case, even if there was no format defined inside the job or node configuration. I will file a ticket for this issue.

          Thanks @michael and @Malcom,

          Yes, it works fine after specifying proper time pattern.

          It would be great help if author add litle description here in wiki ? as like other plugins.

          Swapnil Kotwal added a comment - Thanks @michael and @Malcom, Yes, it works fine after specifying proper time pattern. It would be great help if author add litle description here in wiki ? as like other plugins.

          Chris Tobey added a comment - - edited

          I tried a test with one of my jobs and the zen-timestamp plugin.

          I had the line "Changing BUILD_ID variable (job build time) with the date pattern yyyy-MM-dd_HH-mm-ss." in my log 10+ times.

          You also have to specify this option in EVERY individual build? How is this at all an acceptable replacement?

          Why can we not make BUILD_TIMESTAMP a Jenkins default variable?

          Chris Tobey added a comment - - edited I tried a test with one of my jobs and the zen-timestamp plugin. I had the line "Changing BUILD_ID variable (job build time) with the date pattern yyyy-MM-dd_HH-mm-ss." in my log 10+ times. You also have to specify this option in EVERY individual build? How is this at all an acceptable replacement? Why can we not make BUILD_TIMESTAMP a Jenkins default variable?

          Jeff Foege added a comment -

          You can specify the format in the Manage Jenkins > Configure System > Global Properties then just pass the Build_Timestamp variable to your Build_ID variable you were using in your scripts. I was able to get this to work exactly without too much code changes. If some other project wants to use a different time stamp format then you will have that ability to change it at the project level.

          Jeff Foege added a comment - You can specify the format in the Manage Jenkins > Configure System > Global Properties then just pass the Build_Timestamp variable to your Build_ID variable you were using in your scripts. I was able to get this to work exactly without too much code changes. If some other project wants to use a different time stamp format then you will have that ability to change it at the project level.

          Michael Rentschler added a comment - - edited

          @Chris
          There is still a bug inside the ZenTimestamp Plugin. Once this is fixed, you do not have to check this option in every Jenkins job configuration.
          It should be enough to install the ZenTimestamp plugin. Then the BUILD_TIMESTAMP variable will be set to its default format.
          So far, until this issue inside the ZenTimestamp plugin was fixed, you have to set it in every job config (like you noticed).
          Or, as a simple workaround, set the ZenTimestamp format on the global Jenkins configuration page. That option should apply for all jobs then. (Jeff was faster here
          Once the plugin was fixed, even this check box is not necessary anymore. See the last comments on the reopened issue JENKINS-26626

          Michael Rentschler added a comment - - edited @Chris There is still a bug inside the ZenTimestamp Plugin. Once this is fixed, you do not have to check this option in every Jenkins job configuration. It should be enough to install the ZenTimestamp plugin. Then the BUILD_TIMESTAMP variable will be set to its default format. So far, until this issue inside the ZenTimestamp plugin was fixed, you have to set it in every job config (like you noticed). Or, as a simple workaround, set the ZenTimestamp format on the global Jenkins configuration page. That option should apply for all jobs then. (Jeff was faster here Once the plugin was fixed, even this check box is not necessary anymore. See the last comments on the reopened issue JENKINS-26626

            jglick Jesse Glick
            applican David Sommer
            Votes:
            20 Vote for this issue
            Watchers:
            33 Start watching this issue

              Created:
              Updated:
              Resolved: