无法使用prd环境上下文中的env变量

问题描述 投票:0回答:1

在存储库创建的环境变量 Var1 中的设置下。

下面是 github 操作,它将再次调用不同存储库中的另一个模板

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: 
  workflow_dispatch:
    inputs:
      Pass_Input:
        description: 'test'
        required: true
        default: "From Github action 2"

jobs:
  call-workflow-passing-data:
    env: prd
    uses: your-org/your-repo/.github/workflows/option1.yml@main
    with:
      MT_NAME: "Calling from Github 2"
      MT_FOLDER: ${{ vars.var1 }}

我收到以下错误:

 Invalid workflow file: .github/workflows/option2.yml#L13
 The workflow is not valid. 
 .github/workflows/option2.yml (Line: 13, Col: 10): Unexpected value 'prd' 
 .github/workflows/option2.yml (Line: 14, Col: 5): Unexpected value 'uses'

GHA的参考模板是:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: 
  workflow_call:
    inputs:
      MT_NAME:
        description: 'MT Name'
        required: true
        type: string
        
      MT_FOLDER:
        type: string
        description: 'MT Folder location'
        required: true

jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - run: echo "${{ inputs.MT_NAME }}"
      - run: echo "${{ inputs.MT_FOLDER }}"
        

请有人帮忙解决这个问题

github github-actions devops cicd
1个回答
0
投票

我认为您不能像您那样在调用工作流程中传递环境,您还需要将其转换为输入。另外,要传递环境,您需要使用

environment:
而不是
env:
,后者用于设置作业级别环境变量,前者用于将作业链接到 github 中定义的环境。我知道,很混乱。

还没有测试过这个,但我相信这应该有效:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: 
  workflow_dispatch:
    inputs:
      Pass_Input:
        description: 'test'
        required: true
        default: "From Github action 2"

jobs:
  call-workflow-passing-data:
    uses: your-org/your-repo/.github/workflows/option1.yml@main
    with:
      MT_NAME: "Calling from Github 2"
      MT_FOLDER: ${{ vars.var1 }}
      environment: 'prd'

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: 
  workflow_call:
    inputs:
      MT_NAME:
        description: 'MT Name'
        required: true
        type: string
        
      MT_FOLDER:
        type: string
        description: 'MT Folder location'
        required: true

      environment:
        type: string
        required: true

jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - run: echo "${{ inputs.MT_NAME }}"
      - run: echo "${{ inputs.MT_FOLDER }}"
© www.soinside.com 2019 - 2024. All rights reserved.