runner: Secrets cannot be used to condition job runs
Describe the bug
The secrets
context is apparently not available to if
conditional expressions on jobs.
To Reproduce Create and trigger a workflow with jobs conditioned on the value of a secret:
jobs:
build_bulky_stuff:
if: ${{ secrets.BUILD_BULKY_STUFF == 'true' }}
# ...
Here’s a real world example.
Expected behavior
The condition is successfully evaluated and if the secret value is set to 'true'
, the job is run.
Runner Version and Platform
Version of your runner? No idea, GitHub hosted.
OS of the machine running the runner? Linux
What’s not working?
The workflow fails with:
The workflow is not valid. .github/workflows/release.yml (Line: 11, Col: 9): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.BUILD_RELEASES == 'true',.github/workflows/release.yml (Line: 35, Col: 9): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.BUILD_RELEASES == 'true'
Job Log Output
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 33
- Comments: 22 (2 by maintainers)
Commits related to this issue
- Use envvar in action to determine secrets This will make dependabot run external tests. It would be neat to just check if the secret exists, but you can't do that in an if expression: https://github... — committed to bfirsh/keepsake by bfirsh 4 years ago
- CI: Run package job only if Github secrets are available following a trick learned from https://github.com/actions/runner/issues/520 — committed to entropia/tip-toi-reveng by nomeata 4 years ago
- Don't try to send a ci-passed event in forks Forks don't have access to the main repo's secrets. When a branch on a fork is pushed to, CI still runs, but the last step of sending out the CI success e... — committed to carlobeltrame/ecamp3 by carlobeltrame 4 years ago
- gh actions can't condition on secret, so we have to set an output https://github.com/actions/runner/issues/520 — committed to avrae/avrae by zhudotexe 3 years ago
- Secrets cannot be used in job conditions https://github.com/actions/runner/issues/520 — committed to charmed-kubernetes/actions-operator by johnsca 3 years ago
- https://github.com/actions/runner/issues/520 — committed to berberman/haskell-language-server by berberman 3 years ago
- CI: Improve how images workflow works in forks Use the respository owner name rather than hardcoding 'mesonbuild' Don't run this workflow if docker credentials aren't in secrets (has to be written r... — committed to jon-turney/meson by jon-turney 3 years ago
- CI: Improve how images workflow works in forks Use the respository owner name rather than hardcoding 'mesonbuild' Also don't try to push to docker if docker credentials aren't in secrets (has to be ... — committed to jon-turney/meson by jon-turney 3 years ago
- CI: Don't try to push docker image in a forked repository The 'build images' workflow runs on a schedule, so will run (and fail) weekly in every fork. Don't try to push to docker if docker credentia... — committed to jon-turney/meson by jon-turney 3 years ago
- CI: Don't try to push docker image in a forked repository The 'build images' workflow runs on a schedule, so will run (and fail) weekly in every fork. Don't try to push to docker if docker credentia... — committed to jon-turney/meson by jon-turney 3 years ago
- CI: Don't try to push docker image in a forked repository The 'build images' workflow runs on a schedule, so will run (and fail) weekly in every fork. Don't try to push to docker if docker credentia... — committed to mesonbuild/meson by jon-turney 3 years ago
- Move conditional run to each step Since we can't use the condition on a secret at the job level: https://github.com/actions/runner/issues/520 — committed to devlooped/vsgallery by kzu 2 years ago
- Move conditional run to each step Since we can't use the condition on a secret at the job level: https://github.com/actions/runner/issues/520 — committed to devlooped/vsgallery by kzu 2 years ago
- Move conditional run to each step Since we can't use the condition on a secret at the job level: https://github.com/actions/runner/issues/520 — committed to devlooped/vsgallery by kzu 2 years ago
- Move conditional run to each step Since we can't use the condition on a secret at the job level: https://github.com/actions/runner/issues/520 — committed to devlooped/vsgallery by kzu 2 years ago
- GitHub CI [Coverity]: fixed workflow run Checked the copied secret to env as described here: https://github.com/actions/runner/issues/520#issuecomment-860043020 Fixed failed run coverity-scan #79. — committed to MartinPulec/UltraGrid by MartinPulec 2 years ago
- GitHub CI Coverity: move conditional to every step See also: https://github.com/actions/runner/issues/520 — committed to CESNET/UltraGrid by MartinPulec 2 years ago
- wip https://github.com/actions/runner/issues/520#issuecomment-907770967 — committed to camunda/camunda-platform-helm by Zelldon 2 years ago
- CI: restrict the cloud-cleanup jobs to the base repository In forks there won't be secrets, so the cleanup jobs will fail. I tried checking if the secret are available instead of checking the reposit... — committed to canonical/ubuntu-pro-client by paride 2 years ago
- CI: check if credentials are available before cloud operations Apparently we can't simply check that github.repository == 'canonical/ubuntu-advantage-client' as in PRs github.repository is the *t... — committed to paride/ubuntu-advantage-client by paride 2 years ago
I don’t think we should support
secrets
inif
conditional expression since you can’t debug the expression evaluation result.Today we printout debug info for evaluating condition, so when the condition result is not what you expected, you can base on the log to figure out whether it’s a bug in the system or you provide the wrong input.
Ex:
@TingluoHuang My use case is slightly different: I would like to skip steps that interact with an external service e.g. package repository if the API token is not present. It would be enough to be able to check if the secret exists, without inspecting the value. Any chance of that happening? It would be especially useful for project templates: Users often push their projects to a new GitHub repository before configuring the secrets.
@mzabaluev you can do something like this.
then if you want to run those costly steps, just put
RUN TEST
as part of your commit message.I hope this can help.
Thanks @ErinHales and @kis9a!
I had to verify multiple secrets so I found it easier to use bash instead of defining each secret as a environment variable and using the
jobs.<job_id>.if
conditional to know whether the job output has to be set or not:What do you think?
In my opinion there’s still a need for users to be able to conditionally run jobs based on whether they have access to certain secrets or not. I’ve tried to come up with the most concise way to do so within the current limitations, but feel it’s still way too verbose.
I’ve opened an issue here: https://github.com/actions/runner/issues/1138, that illustrates the most concise way I could come up with to check for secrets, as well as a feature request to allow users to check for the existence of secrets in a more concise manner. Hopefully it’ll be of help!
secrets have global scope of visibility just by their nature. Supporting them on step level while not supporting on job level is inconsistency. Telling people that they do not need them while they do is just a way to cover some other reasons for not implementing it.
I do want secrets to be available on job level to avoid failed jobs which are not supposed to run because user decided not to configure or disable a job temporarily while keeping the job configuration in place. Because of not having this feature I will have add if condition to every step of the job.
Did anyone try assigning a secrets value to an output?
Thank you, it was helpful. However, one point correction was necessary.
I see. I assumed the secrets can be used in lieu of per-repository configuration values settable by the administrator, similar to how the
ACTIONS_STEP_DEBUG
secret is used by the runner to enable logs.My need is to disable costly and potentially annoying actions in forks, unless the administrator of the fork enables them. We currently use
if: ${{ github.repository_owner == 'our_org' }}
, but it is annoying to have to disable these conditions in the workflow file when you need to test the workflows.This is really inconvenient to not support secrets as I want to do optional logins for docker builds to different registries in a reusable workflow, depending on which secrets were passed into the workflow.
For now I’ve worked around the issue by using a similar technique to above, but secrets should really be supported in expressions, just like env should be supported in
with
blocks.We did this by copying the secret to an environment variable first:
Took me a while to come up with a solution that worked for my use case. I created a check-env job, hope this helps someone!
Yeah so that is on the step level right? In my testing this approach doesn’t work on a job level, which is specifically what I’m after (assuming that your comment was in response to mine btw, if not please ignore).
No, this does not expose secrets in debug logs. I just verified this; the secrets are replaced with
***
in the debug log as they should be: https://github.com/mixxxdj/vcpkg/runs/3332915402#step:12:1A disadvantage of this approach is that the value shows up in debug logs and may leak out.
Maybe a function like
secretExists('MY_SECRET')
would be a good middle ground.Ok, I only tried to use it as an output of a job, not a step, maybe that was the problem. Not sure.
You cannot use a secret in an output. Only star characters will be printed