在Github Actions:动态选择基于下拉选择的环境值



在Github Actions中无法根据输入下拉选项选择Environment值

# This is a basic workflow to help you get started with running Fortify scans using ScanCentral into Fortify SSC
name: Namelink Scan
# Controls when the workflow will run
on:
workflow_dispatch:
inputs:
choice:
type: choice
description: Please select the project to scan
options:
- Factorysite
- HouseSite
env:
Factorysite: "https://company.com"
HouseSite: "https://house.com"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "Scan"
Scan:
# The type of runner that the job will run on
runs-on: windows-latest
environment:
name: Test
url: ${{ env.${{ inputs.choice }} }}
steps:
- uses: actions/checkout@v3

错误:

The workflow is not valid. .github/workflows/Namelink.yml (Line: 27, Col: 12): Unexpected symbol: '${{'. Located at position 5 within expression: env.${{ inputs.choice

我尝试修改环境部分不同的方式,但没有工作,如下所述

environment:
name: Test
url: ${{env.echo ${{ inputs.choice }}}}

尝试使用格式表达式:

例子:

url: ${{ format('env.{0}', inputs.choice) }}

我正在寻找的确切输出是使用下面提到的上下文实现的。

environment:
name: Test
url: ${{ env[inputs.choice] }}

最新更新