Jenkins

How to Find Your Jenkins Build Number

Jenkins is a free and open-source automation server that helps automate the parts of the software development process. It provides hundreds of plugins to support building, deploying, and automating any project.

In Jenkins, we work by setting up the various steps of a given application. This works with the help of a Jenkins job which refers to a Jenkins compilation based on a given configuration inside a project workspace. Each run of a Jenkins job is known as a build, and each step in a build is known as a build step.

A build can be initiated manually by the user or by an automatic trigger based on a defined condition. Jenkins allows you to specify the various parameters that trigger a build such as commit, scheduled time, or more.

The result of a Jenkins build can be a success or a failure, depending on the results of each build step. The build is considered a success if all the build steps are successful. It is otherwise considered fail if any of the build steps fail.

What Is a Jenkins Build Number?

In Jenkins, a build number refers to a unique identifier which is assigned to a job or task in Jenkins. In every instance that a build is triggered (manually or automatically), Jenkins sets a sequential number to denote that build.

The build number is assigned sequentially, starting with one and increases by 1 for each subsequent build invoked.

The build number helps identify and reference the specific builds, especially when a job or task has multiple builds over time.

For example, if you have a specific item that is run five times, the build numbers for each build ranges from 1, 2, 3, 4, and 5. We can then reference each build number to gather an information about the build information.

In most cases, you may find the build number which is included in the description of each build, allowing you to quickly and easily locate each build.

Using this tutorial, you will learn how you can determine the build number of a given build in Jenkins.

Find the Build Number in Jenkins

To find the build number in Jenkins, log into the Jenkins interface.

http://localhost:8080

Feel free to change the provided address if your Jenkins instance is running on a custom address.

Once logged in, navigate to the “Build History” section.

This should open a timeline of all previous builds for the given pipeline. Next, select the “Build” from the list of prior builds. Click it to view the build information.

On the build information page, you will find the various information and actions that you can take on the build. For example, you can find the console output from the build, the pipeline steps, restart the build, and more.

Find the Build Number Using the Jenkins CLI

To find the build number of a job in Jenkins using the command-line interface (CLI), we can use the CURL command and query the XML endpoint for the build number of the last successful build.

Suppose we have a job called websocket-chat and we wish to find the build number of the last successful build. We can run the following request:

curl --user root:password http://localhost:9001/job/websocket-chat/api/xml?xpath=/*/lastSuccessfulBuild/number

Feel free to replace the previous command with your target Jenkins address, username and password, and job name.

Running the previous command should return the build number in the XML format as shown in the following:

<number>7</number>

Conclusion

You came across the various techniques to determine the build number in Jenkins in this post. It is good to note a few things about the Jenkins build number:

  1. The build number is not necessarily a serial number. For example, if a build is deleted or removed, the build numbers of subsequent builds will not be affected.
  2. The build number is not necessarily a serial number. For example, if a build is deleted or removed, the build numbers of subsequent builds will not be affected.
  3. Jenkins allows you to customize the build number format in the job configuration file. This enables you to add a custom meta info such as date and time.
  4. You can reset the build number by selecting the reset build number on the job config page.

We hope you enjoyed this tutorial. Check out our Jenkins series to discover more about CI/CD using Jenkins.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list