-
Hi! I’m looking for a way to pass parameters to GitHub Actions without hard coding it into the yaml file. This is because I’d like to reuse the yaml across projects. Is this possible? For Contextmy yaml file builds a docker image and publishes it to the GitHub Container Registry and it works fine. However, currently I’m using the repository name for the name of the docker image. I’d like to arbitrarily set this value without writing it in the yaml file. With Travis CI, you have the ability to set environment variables per repository in the dashboard, then use that variable. Is this possible with GitHub Actions? I have an alternative solution regardless; I’m just wondering if this is possible before trying something else. Help is appreciated, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
In principle you could use secrets to store your variables. However, as long as you need only the repository name you can get that from the |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for the reply! Yeah, I tried this previous but unfortunately it didn’t work unfortunately for some reason. It does not appear to let you use secrets arbitrarily like that. the docker image format is ghcr.io/:organisation/:image-name::version, where e.g.:
This will comfortably release a docker image who’s name matches the repository. the release_name step is:
Which executes fine, but cannot be used in the build step because it won’t output secrets like that, I think. Give us a shout if you come up with anything else. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Not sure if it helps, but I want to add that if you manually invoke runs ( |
Beta Was this translation helpful? Give feedback.
-
You can set an environment variable using
Then use it in the next steps:
Hope that helps. ✌️t4: |
Beta Was this translation helpful? Give feedback.
-
@eiymba , In the workflow, you can use the default environment variable ‘GITHUB_REPOSITORY’ to get the owner and repository name (owner-name/repo-name).
If you want to only get the owner name, you can use the expression ‘${{ github.repository_owner }}’ to get it from the github context.
The following is an example as reference: https://github.com/TestWorkflowsRML/GHA-Syntax/actions/runs/264370292/workflow#L21 |
Beta Was this translation helpful? Give feedback.
-
Hi @ghostwriter ! Thanks a lot of taking a look at this. <3 I’ve tried this solution before but the build process does not appear to echo secrets when used in this manner. It’s entirely omitted for me. Give us a shout if you have any more ideas! Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hey @brightran thanks a lot for taking a look at this! <3 This is currently the solution I’m already using. I’m looking to use an arbitrary name at build time instead of the repository name, without writing it in the yaml file, and setting this as a secret does not appear to work. For example, if my repository is called Give us a shout if you have any more ideas! Thanks again! |
Beta Was this translation helpful? Give feedback.
-
This might be the best approach thus far! It works but the only down side is, it’s not automatically triggered. Thanks for taking a look at this! <3 |
Beta Was this translation helpful? Give feedback.
-
I’ve found a solution. I create a separate workflow which generates an artefact, and then I can check to see if it’s available for my release workflow. to consume. I’ll make a write up when I have time. Thanks for your help, everyone! |
Beta Was this translation helpful? Give feedback.
I’ve found a solution.
I create a separate workflow which generates an artefact, and then I can check to see if it’s available for my release workflow. to consume.
I’ll make a write up when I have time.
Thanks for your help, everyone!