在 GitHub 操作中调用可重用工作流时,秘密插值在调用者工作流中给出语法错误
Secret interpolation is giving syntax error in caller workflow when calling a resusable workflow in GitHub Action
我正在使用 reusable workflow,当将 secrets
从调用方工作流传递到可重用工作流时,出现以下语法错误:
The workflow is not valid. .github/workflows/caller_workflow.yml (Line: 28, Col: 28): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.SECRET_1 .github/workflows/caller_workflow.yml (Line: 29, Col: 22): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.SECRET_2
不确定为什么插值不起作用。
这是我的呼叫者工作流程caller_workflow.yml
(给出上述错误):
name: Build workflow
on:
push:
branches:
- dev
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
- dev
jobs:
# reference: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#example-caller-workflow
org-checks:
uses: repo/.github/workflows/main_workflow.yml@main
with:
SECRET_1: ${{ secrets.SECRET_1 }}
SECRET_2: ${{ secrets.SECRET_2 }}
这是我的可重用工作流程:
name: CI workflow
on:
workflow_call: # enables this workflow to be reusable for other repo
secrets:
SECRET_1:
description: 'secret 1'
SECRET_2:
description: 'secret 2'
push:
branches:
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
jobs:
job-name-to-run:
...... ......
其他流程中的秘密使用相同的语法都可以正常工作。
我以错误的方式传递了秘密。在我的工作流程中,机密是使用 with
输入参数传递的,因此会出现错误。 with
在将输入传递给调用的(可重用的)工作流时可以正常工作,但不适用于机密。
要传递秘密,请使用 secrets
参数。
此处更新caller_workflow.yaml
:
name: Build workflow
on:
push:
branches:
- dev
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
- dev
jobs:
# reference: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#example-caller-workflow
org-checks:
uses: repo/.github/workflows/main_workflow.yml@main
secrets:
SECRET_1: ${{ secrets.SECRET_1 }}
SECRET_2: ${{ secrets.SECRET_2 }}
(删除了 with
并添加了 secrets
)
我正在使用 reusable workflow,当将 secrets
从调用方工作流传递到可重用工作流时,出现以下语法错误:
The workflow is not valid. .github/workflows/caller_workflow.yml (Line: 28, Col: 28): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.SECRET_1 .github/workflows/caller_workflow.yml (Line: 29, Col: 22): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.SECRET_2
不确定为什么插值不起作用。
这是我的呼叫者工作流程caller_workflow.yml
(给出上述错误):
name: Build workflow
on:
push:
branches:
- dev
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
- dev
jobs:
# reference: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#example-caller-workflow
org-checks:
uses: repo/.github/workflows/main_workflow.yml@main
with:
SECRET_1: ${{ secrets.SECRET_1 }}
SECRET_2: ${{ secrets.SECRET_2 }}
这是我的可重用工作流程:
name: CI workflow
on:
workflow_call: # enables this workflow to be reusable for other repo
secrets:
SECRET_1:
description: 'secret 1'
SECRET_2:
description: 'secret 2'
push:
branches:
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
jobs:
job-name-to-run:
...... ......
其他流程中的秘密使用相同的语法都可以正常工作。
我以错误的方式传递了秘密。在我的工作流程中,机密是使用 with
输入参数传递的,因此会出现错误。 with
在将输入传递给调用的(可重用的)工作流时可以正常工作,但不适用于机密。
要传递秘密,请使用 secrets
参数。
此处更新caller_workflow.yaml
:
name: Build workflow
on:
push:
branches:
- dev
- main
pull_request:
types:
- opened
- edited
- reopened
branches:
- main
- dev
jobs:
# reference: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#example-caller-workflow
org-checks:
uses: repo/.github/workflows/main_workflow.yml@main
secrets:
SECRET_1: ${{ secrets.SECRET_1 }}
SECRET_2: ${{ secrets.SECRET_2 }}
(删除了 with
并添加了 secrets
)