Home > Development Tools > git > how to get build number in github actions

how to get build number in github actions

DDD
Release: 2024-10-10 11:15:25
Original
426 people have browsed it

This article provides an overview of methods for obtaining the build number in GitHub Actions workflows. The ${{github.run_number}} context variable is commonly used, while additional options include the env function and Actions Toolkit. Practical us

how to get build number in github actions

How to get build number in GitHub Actions

How do I retrieve the build number in GitHub Actions workflows?

To retrieve the build number in GitHub Actions workflows, you can use the ${{github.run_number}} context variable. This variable is automatically set for every workflow run and represents the unique identifier for that particular run. It is a sequential number that starts from 1 for the first run and increments with each subsequent run.

What methods are available to obtain the build number in GitHub Actions?

There are several methods available to obtain the build number in GitHub Actions:

  • Using the ${{github.run_number}} context variable: This is the most straightforward method and can be used anywhere within a workflow file.
  • Using the env function: You can use the env function to access the build number as an environment variable. For example, ${{env.GITHUB_RUN_NUMBER}}.
  • Using the getBuildNumber() function from the Actions Toolkit: If you are using the Actions Toolkit, you can use the getBuildNumber() function to retrieve the build number.

How can I access the build number in GitHub Actions for specific use cases?

There are various ways to access the build number in GitHub Actions depending on your specific use case:

  • Displaying the build number in the workflow log: You can use the echo function to display the build number in the workflow log. For example, echo "Build number: ${{github.run_number}}".
  • Setting the build number as an output: You can set the build number as an output of a job and then use it in subsequent jobs. For example, steps: - run: echo "Build number: ${{github.run_number}}" outputs: build_number: ${{steps.run.outputs.message}}.
  • Accessing the build number in a script: You can access the build number in a script by using the ${{github.run_number}} variable within the script code.
  • Using the build number as a parameter in other actions: You can pass the build number as a parameter to other actions by using the with keyword. For example, uses: actions/upload-artifact@v2 with: name: my-artifact path: my-path run-number: ${{github.run_number}}.

The above is the detailed content of how to get build number in github actions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template