Make action use environment based on branch name #56123
-
Select Topic AreaGithub environments integration into jobs BodyHi all, I've been trying to run a github action on an environment based on branch name. Unfortunately, I'm unable to dynamically set the environment name using the branch name. name: Docker Image CI
on:
push:
branches: [ "main", "staging" ]
pull_request:
branches: [ "main", "staging" ]
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${GITHUB_REF##*/}
steps:
- uses: actions/checkout@v3
- name: Set environment variables
run: echo PORT ${{ vars.PORT }} && echo PORT ${{ env.PORT }}
- name: Build the Docker image
run: docker build . --file Dockerfile --tag express:${GITHUB_REF##*/} Does someone know how I could do this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
This is Bash syntax, which isn't available outside environment:
name: ${GITHUB_REF##*/} You need to use Actions syntax instead. It looks like environment:
name: ${{ github.ref_name }} |
Beta Was this translation helpful? Give feedback.
-
There is an example on how to use the branch name to select secrects in the docs: env:
MY_ENV_VAR: ${{ github.ref == 'refs/heads/main' && 'value_for_main_branch' || 'value_for_other_branches' }} https://docs.github.com/en/actions/learn-github-actions/expressions#example |
Beta Was this translation helpful? Give feedback.
-
Here is a multiline variant (from here): environment: |-
${{
github.ref_name == 'master' && 'production'
|| github.ref_name == 'dev' && 'dev'
|| 'staging'
}} , where the dash in |
Beta Was this translation helpful? Give feedback.
-
Mold-inspection-kc is crucial for maintaining a healthy indoor environment. This process involves assessing properties for mold growth and identifying potential moisture sources. Trained inspectors utilize advanced tools to detect hidden mold and evaluate air quality. During an inspection, samples may be taken for laboratory analysis to determine mold types and concentrations. Homeowners and businesses can benefit from mold inspections by addressing issues early, preventing health risks, and protecting property value. Regular inspections are recommended, especially in areas prone to moisture, ensuring a safe living or working space. |
Beta Was this translation helpful? Give feedback.
This is Bash syntax, which isn't available outside
run
steps using Bash as the shell.You need to use Actions syntax instead. It looks like
github.ref_name
should be what you need: