Create a new env var for the branch name
See original GitHub issueDescribe the enhancement We already have access to the branch/PR/tag ref name which is good but having an easy way to get the actual branch name is a really important feature.
Gitlab has two very good variables for that: (by the way, they very handy for me)
CI_COMMIT_REF_NAME
for the branch/tag nameCI_COMMIT_REF_SLUG
a slug for the branch/tag name
Ref: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference
One of my use cases is to tag a Docker image based on the branch name.
Additional information Here is a list of questions on the web about it and how this can lead to different implementations prone to error:
- https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
- https://stackoverflow.com/questions/58886293/getting-current-branch-and-commit-hash-in-github-action?noredirect=1&lq=1
- https://github.community/t5/GitHub-Actions/How-to-get-PR-branch-name-in-GitHub-Actions/td-p/35041#
- https://github.com/igordcsouza/github-action-get-branch-name
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Choose an environment variable based on the branch ...
Based on the current branch name, I have to pick the correct environment variable, and store its value (mail ID) to another environment...
Read more >Dynamically set environment var based on branch name
I need some way to set an ENV var that can be used in my config.yml file to represent either “staging” or “production”...
Read more >Environment variables - AWS Amplify Hosting
Amplify environment variablesSet environment variablesAccess environment variables at build ... The branch Amazon Resource Name (ARN) of the current build.
Read more >Introduction to environment variables
Use environment variables to set up various configuration options, ... run: # print the name of the branch we're on name: "What branch...
Read more >Environment Variables
A common way to customize the build process is to define environment variables, which can be accessed from any stage in your build...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tony been a while since I looked at this but I ended up with something along these lines:
Hope that helps!
Hi everyone!
While reading comments, it seems like it has been resolved. I am closing this issue now but feel free to re-open it or file another issue if this matter is not resolved 😊.