-
Dear everyone, I want a workflow to only be run if a secret is available. In pseudocode: if secret.available: Does anybody have any ideas and examples? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can use the APIs “List repository secrets” and “List organization secrets” to get the total count of the repository-level secrets and organization-level secrets. Then according to the total count to determine whether to continue the subsequent jobs. To run these two APIs, you need to create a personal access token (PAT) that has the repo scope (access repository-level secrets) and admin:org scope (access organization-level secrets), and set this PAT as a secret in the repository or in the organization. Then you can use this PAT to authenticate in the workflow. Due to the added authorization PAT, there is an existing secret at least. If you want to ignore the PAT in the secrets, you can set the available count to be more than 1. If the count is equal or less than 1, you can determine it as “No available secrets”. TestWorkflowsRML/RunAPIContribute to TestWorkflowsRML/RunAPI development by creating an account on GitHub.
When the total count of the secrets (repository-level and organization-level) is equal or less than 1, set job1 to be failed with the error message “No available secrets!”. Then the subsequent jobs (job2 and job3) will be skipped. |
Beta Was this translation helpful? Give feedback.
-
Here’s a related question with alternative solutions: How can I test if secrets are available in an action? |
Beta Was this translation helpful? Give feedback.
@zethson,
You can use the APIs “List repository secrets” and “List organization secrets” to get the total count of the repository-level secrets and organization-level secrets. Then according to the total count to determine whether to continue the subsequent jobs.
To run these two APIs, you need to create a personal access token (PAT) that has the repo scope (access repository-level secrets) and admin:org scope (access organization-level secrets), and set this PAT as a secret in the repository or in the organization. Then you can use this PAT to authenticate in the workflow.
Due to the added authorization PAT, there is an existing secret at least. If you want to ignore the PAT in the secre…