Home > other >  Using env variable github.ref_name doesn't give me branch name
Using env variable github.ref_name doesn't give me branch name

Time:01-30

When I use in my workflow github.ref_name it doesn't provide me a branch name from where I triggered this workflow. I get 16/merge. Why? When I use github.ref_type I clearly see that my ref type is branch so why I don't get branch name?

Also it's showing when I use $GITHUB_REF or git symbolic-ref HEAD (and separating refs/heads/ off). Ah and I tried github.event.push.ref but it's not showing me anything.

How to get always branch name from where I triggered the workflow?

CodePudding user response:

For following code:

Run echo running on branch ${GITHUB_REF##*/} ${GITHUB_REF}

When your workflow runs becuase of push event you will get:

running on branch main refs/heads/main

But for pulr request event it would be:

running on branch merge refs/pull/3/merge

Why's that?

If the repository is on GitHub and you have any Pull Requests that have been opened, you’ll get these references that are prefixed with refs/pull/. These are basically branches, but since they’re not under refs/heads/ you don’t get them normally when you clone or fetch from the server — the process of fetching ignores them normally.

You can also check this question here

  •  Tags:  
  • Related