How to Set Dynamic Release URLs in Environment with GitHub Actions
kosei
Posted on March 7, 2024
Introduction
This article explains how to dynamically set a release URL in an Environment using GitHub Actions.
Background
GitHub Actions has a feature for defining environments called Environment.
Using environments for deployment - GitHub
For example, by setting up environments like the following, it's possible to switch the release destination. (You can set any name you want.)
- Production environment
- Staging environment
- Testing environment
- Development environment
Among these, there is a function to display the URL of the release destination after releasing.
If there's only one fixed environment, it's not a problem. However, if the URL is determined dynamically during the release steps, it was unclear how to display it, so I'm documenting the method here.
If it's a single environment, you can set the URL as follows.
environment:
name: production
url: https://example.com
How To
The method is simple: save the value in an output during the step when the URL is confirmed, and then set that output as the environment's URL.
Here is a sample Yaml. You need to assign a reference ID to the step. The format for referencing the output is steps.[step_id].outputs.[output_name]
.
environment:
name: development
url: ${{ steps.get_release_url.outputs.release_url }}
steps:
- name: Set release url
id: get_release_url
run: echo release_url=https://xxx.example.com >> $GITHUB_OUTPUT
Conclusion
The method to dynamically set the URL of a release in GitHub Actions' Environment is to save a value in the output during the release step, and then set that output name as the URL in the environment.
Posted on March 7, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 26, 2024
September 12, 2024