Search code examples
githubyamlgithub-actionsworkflowcicd

Use selected branch on github workflow


I want to have the value of the selected branch on the GitHub workflow run; I know that I can define another input for the branch and read it, but I don't want to do that; I want to read the selected branch.

enter image description here

Something like this?!

name: Get selected branch
run-name: "Running on @${{ inputs.SELECTED_BRACNH }}"
on:
  workflow_dispatch:

Solution

  • To use the name of the GitHub Branch in the workflow it's not needed an input, you can use the Default environment variables.

    Specifically for the branch name you can use

    • GITHUB_REF, The fully-formed ref of the branch or tag that triggered the workflow run.
    • GITHUB_REF_NAME, The short ref name of the branch or tag that triggered the workflow run.