GitHub Actions工作流间仓库路径参数传递失败问题
问题分析与解决方法
问题根源
你在A工作流传递repo_name时,直接写了$GITHUB_REPOSITORY,未使用GitHub Actions的表达式语法包裹,导致该变量没有被解析为实际的{owner}/{repo}格式仓库路径,而是以字面量字符串$GITHUB_REPOSITORY传递给B工作流,最终触发checkout动作的格式错误。
修复步骤
修改A工作流中repo_name的赋值方式,用表达式语法${{ GITHUB_REPOSITORY }}包裹变量,让GitHub Actions正确解析该环境变量:
jobs: Reuse: uses: org/repo/.github/workflows/b_workflow.yml with: enviroment_name: SANDBOX repo_name: ${{ GITHUB_REPOSITORY }} secrets: token: ${{ secrets.SOURCE_REPO_TOKEN }}
额外优化建议(可选)
注意到你在A工作流中传递了enviroment_name参数,但B工作流的workflow_call输入定义里未包含该字段。如果需要使用传递的环境名称,可在B工作流中补充对应定义并引用:
on: workflow_call: inputs: repo_name: type: string required: true description: "REPO Name" enviroment_name: type: string required: true description: "Environment Name" build: runs-on: ubuntu-latest environment: name: ${{ inputs.enviroment_name }} steps: - uses: actions/checkout@v3 with: repository: ${{ inputs.repo_name }} ref: test token: ${{ secrets.token }} path: source
内容的提问来源于stack exchange,提问作者Lex
相关产品推荐
相关产品推荐

