Master GitHub Actions Build Number In Seconds

Logan Jul 13, 2026

Embarking on your GitHub Actions journey, you've likely come across the need to obtain the build number. This can be incredibly useful for versioning, artifact identification, or keeping a build history. In this guide, we'll explore how to achieve this using GitHub Actions features and best practices.

Nikki Siapno on LinkedIn: GitHub Actions — How do you optimize their performance? GitHub Actions is…
Nikki Siapno on LinkedIn: GitHub Actions — How do you optimize their performance? GitHub Actions is…

GitHub Actions offers a wealth of context and data for each running job, allowing you to access information like run numbers, event types, and more. Among these, retrieving the build number, or run number, can be easily accomplished using built-in environment variables.

How GitHub Actions 10x my productivity
How GitHub Actions 10x my productivity

Understanding GitHub Actions Environment Variables

GitHub Actions provides a plethora of environment variables that you can leverage to access run metadata. These variables are prefixed with `GITHUB_` and can be used directly in your workflow files without any additional setup.

A Beginners Guide to CI/CD with GitHub Actions
A Beginners Guide to CI/CD with GitHub Actions

To learn more about these environment variables and their possible values, you can refer to the official GitHub documentation: https://docs.github.com/en/actions/learn-github-actions/environment-variables

Finding the Run Number

a laptop computer sitting on top of a desk next to a cup of coffee and pen
a laptop computer sitting on top of a desk next to a cup of coffee and pen

The run number, also known as the build number, can be accessed using the `GITHUB_RUN_NUMBER` environment variable. This variable contains the number of times a workflow has been run in the repository. It increments by one each time the workflow is triggered.

For example, if you've run your workflow 5 times, the `GITHUB_RUN_NUMBER` will be `6` for the next run, as it starts counting from 1.

Accessing the Run Number in Your Workflow

Github Actions Sticker
Github Actions Sticker

To use the `GITHUB_RUN_NUMBER` in your workflow, you simply need to echo or print its value in your desired format. Let's see how you can achieve this using different programming languages.

For Bash scripts, you can use the `echo` command:

```bash echo "Build Number: ${{ env.GITHUB_RUN_NUMBER }}" ```

For PowerShell scripts, you can use the Write-Output cmdlet:

Git Workflow Roadmap
Git Workflow Roadmap

```powershell Write-Output "Build Number: $env:GITHUB_RUN_NUMBER" ```

For other programming languages or tools, you can use their respective execution methods to print or use the `GITHUB_RUN_NUMBER` in your operations.

Versioning Artifacts Using the Build Number

🤝 Collaborating on GitHub with Remote Repositories
🤝 Collaborating on GitHub with Remote Repositories
25 GIT COMMANDS EVERY DEVELOPER SHOULD MASTER
25 GIT COMMANDS EVERY DEVELOPER SHOULD MASTER
a computer screen with the text stop forgeting git
a computer screen with the text stop forgeting git
Git vs GitHub: Key Differences Every Developer Should Know
Git vs GitHub: Key Differences Every Developer Should Know
GitHub Spark enters public preview to revolutionize app development for all
GitHub Spark enters public preview to revolutionize app development for all
GitHub - SecureStackCo/actions-all-in-one: All of our GitHub Actions rolled into one.  Or as we like to say:  One GitHub Action to rule them all!
GitHub - SecureStackCo/actions-all-in-one: All of our GitHub Actions rolled into one. Or as we like to say: One GitHub Action to rule them all!
the numbers are arranged in different colors and sizes on a computer screen with dark background
the numbers are arranged in different colors and sizes on a computer screen with dark background
an image of a computer screen with code numbers on it and the words output messages
an image of a computer screen with code numbers on it and the words output messages
Master Git Essentials: A Developer's Guide to Version Control 🚀
Master Git Essentials: A Developer's Guide to Version Control 🚀
Git
Git
Building Number Skills with Fun Number of the Week Activities for 1st Grade
Building Number Skills with Fun Number of the Week Activities for 1st Grade
an image of different types of cats
an image of different types of cats
an image of a computer screen with text
an image of a computer screen with text
a laptop computer sitting on top of a desk with the words number of the day google classroom
a laptop computer sitting on top of a desk with the words number of the day google classroom
four different ways to make a number puzzle with numbers and letters on it, including two fingers
four different ways to make a number puzzle with numbers and letters on it, including two fingers
hehe
hehe
Brand identity design for a fintech platform | Sensus
Brand identity design for a fintech platform | Sensus
Let’s Build the Number | Number Bonds Worksheets
Let’s Build the Number | Number Bonds Worksheets
Flames as Microsoft and GitHub are launching a DDoS attack on the server of the open source software 'GNU Multi-Precision Library'
Flames as Microsoft and GitHub are launching a DDoS attack on the server of the open source software 'GNU Multi-Precision Library'
Math Problem Strings and Number Talks in 4th Grade and 5th Grade
Math Problem Strings and Number Talks in 4th Grade and 5th Grade

Now that you've obtained the build number, you can put it to good use, such as versioning your artifacts. This helps in tracking and identifying specific builds and their outputs.

When publishing artifacts, you can append the build number to your artifact name to ensure uniqueness. Here's a simple example using an upload artifact action:

`actions/upload-artifact@v2`

```yaml - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: MyArtifact-${{ env.GITHUB_RUN_NUMBER }} path: ./path/to/my/artifact ```

In this example, the uploaded artifact will be named `MyArtifact-{build_number}`.

Displaying the Build Number in Logs or Notifications

You can also display the build number in your workflow logs or send it as a notification to help keep track of your running jobs. To do this, you can use the `run` command in your workflow file or send a message to a notification channel like Slack or Microsoft Teams.

For example, to send a message to Slack, you can use the `slack pans_WITH_github_action` action:

`Firebase/slack-action`

```yaml - name: Send Slack Notification uses: Firebase/slack-action@v1 env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} with: args: "The build number is ${{ env.GITHUB_RUN_NUMBER }}" ```

Remember to replace `SLACK_BOT_TOKEN` with the name of your Slack bot token secret.

By following these steps, you'll be able to effectively obtain and utilize the build number in your GitHub Actions workflows. This information can then be used to version artifacts, track builds, and enhance your overall CI/CD experience.

As you explore GitHub Actions further, you'll find that originality and adaptability are key to unlocking its full potential. So, go ahead, experiment, and build!