简体   繁体   English

如何在 github 操作中获取主机存储库的 GitHub 机密作为输入?

[英]How to get GitHub secrets of host repository as input in github action?

We have a repository named recent-activity which hosts a GitHub action and is available for use to all GitHub users.我们有一个名为recent-activity的存储库,它托管 GitHub 操作,可供所有 GitHub 用户使用。 We want to add a URL on which we can send http requests when the action is run (by any user).我们想添加一个 URL ,当操作运行时(由任何用户),我们可以在其上发送 http 请求。 However, we don't want to disclose the URL publicly.但是,我们不想公开披露 URL。

Is there any way this can be done?有什么办法可以做到这一点?

You can include secrets from your repo into the workflows directly by specifying their name.您可以通过指定名称直接将您的存储库中的机密包含到工作流中。 Let's say you have a secret named URL then you can simply use it like:假设您有一个名为URL的秘密,那么您可以像这样简单地使用它:

env:
     URL: ${{ secrets.URL }}

Now your URL is fetched and you can use it in other commands like this $URL现在您的 URL 已获取,您可以在其他命令中使用它,例如$URL

You'll find on the official documentation everything you need about Github Secrets您可以在官方文档中找到有关Github Secrets的所有信息

Note that the repository users won't have access to the secret, because you need admin permissions to edit secrets' values.请注意,存储库用户将无权访问密钥,因为您需要admin权限才能编辑密钥的值。 Moreover, secrets won't be shown on the action workflow execution (they will be replaces by *** in logs).此外,秘密不会显示在操作工作流执行中(它们将在日志中被***替换)。

Everyone will use this secret variable in the workflow the same way, without having access to its value.每个人都将以相同的方式在工作流中使用此秘密变量,而无法访问其值。

Demo演示

日志上的秘密输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM