How do I know If workflow is triggered by git branch or git tag? #26731
-
My workflow run is defined as follows:
How do I know inside my steps that I am currently on a git tag or git branch? And how do I get the name of either of it? Goal: If the workflow is triggered by a git tag, I want to tag my Docker images by the git tag name. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You can use Context to access the information about the workflow run which will include the information you want. For information about trigger, you can use github context: github.ref. Usually, if the workflow is triggered by a tag, the value of github.ref would be something like “refs/tags/xxx”, and if the workflow is triggered by a branch, the value would be “refs/heads/xxx”. And then you can choose your next steps base on this information. |
Beta Was this translation helpful? Give feedback.
-
Hello eddie, |
Beta Was this translation helpful? Give feedback.
-
Daniele-Tentoni:
Git tags are never on a branch, they refer to specific commits independently of branches. Can you clarify what the exact condition is that you’re looking for? Possibly something like “does the branch contain the commit the tag points at”? |
Beta Was this translation helpful? Give feedback.
-
Yes, I was looking for it. My issue was to understand when the commit referred by the tag is in a specific branch. You link had explained me that right. Thank you very much. |
Beta Was this translation helpful? Give feedback.
You can use Context to access the information about the workflow run which will include the information you want. For information about trigger, you can use github context: github.ref. Usually, if the workflow is triggered by a tag, the value of github.ref would be something like “refs/tags/xxx”, and if the workflow is triggered by a branch, the value would be “refs/heads/xxx”. And then you can choose your next steps base on this information.