-
I trigger my workflow using
and I just want the name of the current tag that is just building. Sadly, the
However, I only want the last part, 0.3.1. There exists no function in GitHub Actions that allows me to extract that. Am I overlooking something? How do I get that? |
Beta Was this translation helpful? Give feedback.
Replies: 22 comments 19 replies
-
You can use paramter expansion:
https://stackoverflow.com/questions/9532654/bash-expression-after-last-specific-character |
Beta Was this translation helpful? Give feedback.
-
Nothing indicates that GitHub Actions use bash to evaluate their variables. Are you quite that this is supposed to work? |
Beta Was this translation helpful? Give feedback.
-
You could use actions/github-script
|
Beta Was this translation helpful? Give feedback.
-
Have you tested this? This produced an empty value for me for some reason. |
Beta Was this translation helpful? Give feedback.
-
This is how I’m currently doing it:
Then you have the output of that step and any later step in the job can use this by referring to it either in the run part or in an input.
|
Beta Was this translation helpful? Give feedback.
-
Note that tags can contain a
|
Beta Was this translation helpful? Give feedback.
-
Thanks. Could you add that as a general context/environment variable? It seems to me to be a very common use case and this step of truncating the string is just really annoying IMO. |
Beta Was this translation helpful? Give feedback.
-
At the moment we’re basically populating the data from the webhook. If we start adding additional data beyond that then this seems like a good candidate. Thanks for the feedback! |
Beta Was this translation helpful? Give feedback.
-
I prefer this syntax:
|
Beta Was this translation helpful? Give feedback.
-
My approach is setting three vars: SOURCE_NAME: The branch or the tag SOURCE_BRANCH: The branch or empty SOURCE_TAG: The tag or empty
And to use it, just declare as ENV vars in each task:
Updated: Since |
Beta Was this translation helpful? Give feedback.
-
This is awefull and annoying, I been wasting my time and breaking my head over this for hours. Gitlab has a dead simple straight forward to the point
that gives you a short represenstation of the current build without any charcters you do not want for filename and the likes. Just [a-z0-9-] the fact that we have to use this super ugly and annoying to read syntax
BELOW THE job env declaration sucks. And its not finished there, still need to cut out characters. Github shoud just copy Gitlab here and provide a slug. If anyone has a idea hwo I in a most siple way copy wtat gitlab may to to output the slug I would appreciate it. |
Beta Was this translation helpful? Give feedback.
-
@ethomson how would you do for a Windows runner ? |
Beta Was this translation helpful? Give feedback.
-
I’m not very familiar with PowerShell, so what I’d do is just run it in bash on Windows. You can do this by setting |
Beta Was this translation helpful? Give feedback.
-
> Note that tags can contain a Can they? When I run |
Beta Was this translation helpful? Give feedback.
-
I use this for windows
echo “::set-env name=SOURCE_NAME::$SOURCE_NAME” |
Beta Was this translation helpful? Give feedback.
-
With Windows ( runs-on: windows-latest ) it would be
and you can use it with PowerShell e.g.
|
Beta Was this translation helpful? Give feedback.
-
Any idea how to get the tag name to the artifact file name? I have been trying to use this steps.tag.output.result to the artifact filename but its returing null. |
Beta Was this translation helpful? Give feedback.
-
Any update on that? I’m strugglin because I want to publish artifacts from the build but for some reason they have to be unique. Okay, I can use tag, but there is no variable for it. And I cannot use suggested workarounds becuase i need to use tag in matrix, before all the jobs are run. |
Beta Was this translation helpful? Give feedback.
-
This accepted solution doesn’t seem to work on |
Beta Was this translation helpful? Give feedback.
-
Since this page shows up surprisingly high in Google search , here is the 2022 answer in "How to get a tag name in GitHub Actions"
https://docs.github.com/en/actions/learn-github-actions/contexts#github-context |
Beta Was this translation helpful? Give feedback.
-
I use |
Beta Was this translation helpful? Give feedback.
-
This is May 8 2023, i can confirm |
Beta Was this translation helpful? Give feedback.
Since this page shows up surprisingly high in Google search , here is the 2022 answer in "How to get a tag name in GitHub Actions"
https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables