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 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:
${{github.run_number}}
context variable: This is the most straightforward method and can be used anywhere within a workflow file.env
function: You can use the env
function to access the build number as an environment variable. For example, ${{env.GITHUB_RUN_NUMBER}}
.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:
echo
function to display the build number in the workflow log. For example, echo "Build number: ${{github.run_number}}"
.steps: - run: echo "Build number: ${{github.run_number}}" outputs: build_number: ${{steps.run.outputs.message}}
.${{github.run_number}}
variable within the script code.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!