如何在github工作流中设置秘密,该秘密被注入不在WorkFlow文件夹中的属性文件中

发布于 2025-02-10 09:20:50 字数 625 浏览 1 评论 0原文

我有一个.github/WorkFlow .yml文件,该文件用作GitHub Action Workflow。

请忍受我,我是Github的新手。

每当更改项目中的文件时,我正在研究一个项目,以触发GitHub的构建。我有那一部分工作。但是,有人告诉我,我们不应该有任何包含用户名/密码的文件,并且我们应该用github秘密替换它们。我在某个地方阅读了GitHub秘密仅在.github/WorkFlow目录中的文件上工作的地方。不幸的是,我知道的用户名/密码在.properties文件中,与.github/workflow不同。有没有办法将GitHub秘密注入.github/Workflow中未找到的文件?

一些可能的方法:

  1. 在build.yml文件中,我可以设置一个与github秘密相等的全局环境变量,然后在.properties文件中使用环境变量(例如:$ {$ {env.mypassword}})。那对我不起作用。

  2. 我可以在build.yml文件中调用bash脚本以将其作为输入秘密,然后bash脚本可以继续使用输入附加.properties文件。该秘密将可用于bash脚本,因为它在build.yml文件中,在.github/workflow文件中,在同一外壳中。我还没有尝试过。

I have a .github/workflow .yml file that I am using as a GitHub Action workflow.

Please bear with me I am new to GitHub.

I am working on a project to trigger a build in GitHub whenever a file in the project is changed. I have that part working. However, I was told that we shouldn't have any files that contain username/passwords, and that we should replace them with GitHub secrets. I read somewhere that GitHub secrets only work on files in .github/workflow directory. Unfortunately, the username/passwords I know about are in .properties files, in a different directory than .github/workflow. Is there a way to inject GitHub secrets into a file not found in .github/workflow?

Some possible approaches:

  1. In the build.yml file, I can set a global environment variable equal to the GitHub secret, then use the environment variable in the .properties file (eg: ${{env.mypassword}}). That hasn't worked for me.

  2. I could call a bash script in the build.yml file to take as input the secret, and then the bash script could proceed to append the .properties file with the input. The secret would be available to the bash script since its called within the build.yml file, in the .github/workflow file, in the same shell. I haven't tried this yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思故 2025-02-17 09:20:50

也许您可以向Env注入,然后如您所说的那样发送到您的bash脚本。

  • 示例:
    - name: push change
      env:
        GITHUB_LOGIN: xxx
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        git push https://$GITHUB_LOGIN:[email protected]/$GITHUB_REPOSITORY.git master:master

另外,创建github操作位于位置:

repo->设置/秘密/操作

maybe you can inject with env and then send to your bash script as you said.

  • example:
    - name: push change
      env:
        GITHUB_LOGIN: xxx
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        git push https://$GITHUB_LOGIN:[email protected]/$GITHUB_REPOSITORY.git master:master

also, create github actions is on the location:

repo -> settings/secrets/actions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文