英文:
Github Actions: Is it possible to reference a repository variable or environment variable within "uses" context?
问题
我的目标是在环境变量或我可以在GitHub Web界面中设置的存储库 secrets 中设置所使用的 GitHub Actions 的版本。
例如:
example-job:
runs-on: ubuntu-latest
steps:
- name: example-step
uses: example-repo/example-composite-action@${{ secrets.ACTION_VERSION }}
如果我尝试这样做,我得到一个 Unrecognized named-value: 'secrets'.
我尝试了相同的方法,使用 env
得到了类似的结果。
有没有办法更动态地设置组合操作的版本,而不必每次都进行 PR?
英文:
My goal is to set the version of used github actions within either environment variables or repository secrets I can set within the github web interface.
For example:
example-job:
runs-on: ubuntu-latest
steps:
- name: example-step
uses: example-repo/example-composite-action@${{ vars.ACTION_VERSION }}
If I try this I'm getting a Unrecognized named-value: 'vars'.
I tried the same with env
with a similar result.
Is it somehow possible to set the version of composite action more dynamically without doing a PR everytime?
答案1
得分: 2
在复合操作的URL中无法使用变量。这样做是为了避免在使用流水线中的操作时引发任何破坏性变更。
作为替代方案,您可以使用actions/checkout@v3
来检出您的复合操作存储库,并在流水线中引用本地存储库,例如:
- uses: actions/checkout@v3
- name: Checkout actions repo
uses: actions/checkout@v3
with:
repository: my-org/my-actions
path: my-actions
ref: @${{ vars.ACTION_VERSION }}
- uses: ./my-actions/.github/actions/example-composite-action
英文:
It is not possible to use variables in composite action URLs. And that's to avoid any breaking changes from actions in consuming pipelines.
As an alternative you can use the actions/checkout@v3
to checkout your composite action repository and reference it locally in your pipeline, for example:
- uses: actions/checkout@v3
- name: Checkout actions repo
uses: actions/checkout@v3
with:
repository: my-org/my-actions
path: my-actions
ref: @${{ vars.ACTION_VERSION }}
- uses: ./my-actions/.github/actions/example-composite-action
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论