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

          David Sommer created issue -
          Daniel Beck made changes -
          Link New: This issue is related to JENKINS-24380 [ JENKINS-24380 ]

          I think BUILD_ID should keep the timestamp format. That is the documented behaviour at
          https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
          The BUILD_NUMBER variable gives the build number still.

          The change of format has broken a couple of my deployment scripts that were expecting the date format.

          I did a quick fix to use the old formatting code and that seems to have made things work for me. I have not submitted a pull request because I have not had chance to fully test things. For those who are interested the code is at
          https://github.com/oldelvet/jenkins/tree/jenkins-26520

          Richard Mortimer added a comment - I think BUILD_ID should keep the timestamp format. That is the documented behaviour at https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project The BUILD_NUMBER variable gives the build number still. The change of format has broken a couple of my deployment scripts that were expecting the date format. I did a quick fix to use the old formatting code and that seems to have made things work for me. I have not submitted a pull request because I have not had chance to fully test things. For those who are interested the code is at https://github.com/oldelvet/jenkins/tree/jenkins-26520

          Jesse Glick added a comment -

          BUILD_ID is defined to be the ID of the build, and the ID is now a number rather than a timestamp, so the current behavior is correct. (There are some things in Jenkins which expect a build ID.) Adding a new BUILD_TIMESTAMP variable for the dedicated purpose of representing time is the only option.

          I would actually suggest two such variables:

          • BUILD_TIMESTAMP_LEGACY, with the format of the old IDs and in the server’s local timezone.
          • BUILD_TIMESTAMP, in ISO 8601 format (how-to).

          Note that since builds may now come in at a rate of more than one per second, BUILD_TIMESTAMP_LEGACY could easily be nonunique.

          Jesse Glick added a comment - BUILD_ID is defined to be the ID of the build, and the ID is now a number rather than a timestamp, so the current behavior is correct. (There are some things in Jenkins which expect a build ID.) Adding a new BUILD_TIMESTAMP variable for the dedicated purpose of representing time is the only option. I would actually suggest two such variables: BUILD_TIMESTAMP_LEGACY , with the format of the old IDs and in the server’s local timezone. BUILD_TIMESTAMP , in ISO 8601 format ( how-to ). Note that since builds may now come in at a rate of more than one per second, BUILD_TIMESTAMP_LEGACY could easily be nonunique.
          Daniel Beck made changes -
          Link New: This issue is duplicated by JENKINS-26624 [ JENKINS-26624 ]

          For a quick fix (until BUILD_TIMESTAMP was added as an environment variable) use the EnvInject plugin. Enable the "Prepare an environment for the run" option inside your job configuration and paste the following line into the Groovy script section:

          return [BUILD_TIMESTAMP:currentBuild.getTime().format("yyyy-MM-dd_HH-mm-ss")]

          Take care if you use the zentimestamp plugin. This is not working anymore of course.

          Michael Rentschler added a comment - For a quick fix (until BUILD_TIMESTAMP was added as an environment variable) use the EnvInject plugin. Enable the " Prepare an environment for the run " option inside your job configuration and paste the following line into the Groovy script section: return [BUILD_TIMESTAMP:currentBuild.getTime().format("yyyy-MM-dd_HH-mm-ss")] Take care if you use the zentimestamp plugin. This is not working anymore of course.
          Michael Rentschler made changes -
          Link New: This issue is related to JENKINS-26626 [ JENKINS-26626 ]

          Michael Rentschler added a comment - - edited

          @Jesse:
          With the zentimestamp plugin beeing fixed, there is no need to have a BUILD_TIMESTAMP_LEGACY variable. The purpose of this plugin is to:

          change the Jenkins build timestamp format (provided by the Jenkins BUILD_ID variable)

          So if people need another formatting than the default one, this plugin provides the mechanism to change it.

          Adding milliseconds to the new timestamp variable may not be necessary.
          The BUILD_ID is the better choice for getting a unique identifier.

          Michael Rentschler added a comment - - edited @Jesse: With the zentimestamp plugin beeing fixed, there is no need to have a BUILD_TIMESTAMP_LEGACY variable. The purpose of this plugin is to: change the Jenkins build timestamp format (provided by the Jenkins BUILD_ID variable) So if people need another formatting than the default one, this plugin provides the mechanism to change it. Adding milliseconds to the new timestamp variable may not be necessary. The BUILD_ID is the better choice for getting a unique identifier.

          Chris Tobey added a comment - - edited

          I also used the BUILD_ID to tag artifacts with a date.

          To me BUILD_ID is fine as the BUILD_NUMBER.

          I do still need a global variable with the date, and BUILD_TIMESTAMP seems like the best way to do this, as long as it is the start date and time of the job in the local timezone.

          Can this be added and the documentation updated? As others have said, the documentation still shows that BUILD_ID is giving this date.

          Chris Tobey added a comment - - edited I also used the BUILD_ID to tag artifacts with a date. To me BUILD_ID is fine as the BUILD_NUMBER. I do still need a global variable with the date, and BUILD_TIMESTAMP seems like the best way to do this, as long as it is the start date and time of the job in the local timezone. Can this be added and the documentation updated? As others have said, the documentation still shows that BUILD_ID is giving this date.

          Jesse Glick added a comment -

          mre_mchp agreed, that plugin seems like the right place to host this kind of functionality.

          And yes, it is a core bug if the documentation still suggests that BUILD_ID is a date.

          Jesse Glick added a comment - mre_mchp agreed, that plugin seems like the right place to host this kind of functionality. And yes, it is a core bug if the documentation still suggests that BUILD_ID is a date.

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

              Created:
              Updated:
              Resolved: