在Github Actions中:根据下拉选择动态选择环境值

huangapple go评论69阅读模式
英文:

In Github Actions: Dynamically select the environment value based on Dropdown Choice

问题

在GitHub Actions中,无法根据输入下拉选择来选择环境值。

# 这是一个基本的工作流程,帮助您开始运行使用ScanCentral的Fortify扫描到Fortify SSC

name: Namelink Scan

# 控制工作流何时运行
on:
  workflow_dispatch:
    inputs:
      choice:
        type: choice
        description: 请选择要扫描的项目
        options:
        - Factorysite
        - HouseSite
env:
    Factorysite: "https://company.com"
    HouseSite: "https://house.com"

# 工作流程包括一个或多个可以按顺序或并行运行的作业
jobs:
  # 这个工作流包含一个名为“Scan”的作业
  Scan:
    # 作业将在其中运行的运行器类型
    runs-on: windows-latest
    environment:
      name: Test
      url: ${{ env[${{ inputs.choice }}] }}
    steps:
      - uses: actions/checkout@v3

错误:

工作流程无效。.github/workflows/Namelink.yml(行:27,列:12):意外符号:“${{”。 位于表达式内的位置:env.${{ inputs.choice

我尝试了不同的方式修改环境部分,但像下面所述的方式都没有起作用。

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

In Github Actions unable to select the Environment value based on input dropdown choice.

# 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

Error:

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

I tried modifying the environment section different ways but nothing worked as mentioned below

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

答案1

得分: 1

尝试使用 format 表达式:

示例:

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

Try using the format expression:

Example:

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

答案2

得分: 1

以下是翻译好的内容:

"我要找的确切输出是通过如下所示的上下文实现的。

environment:
  name: 测试
  url: ${{ env[inputs.choice] }}
```"

<details>
<summary>英文:</summary>

The exact output which I am looking is achieved using contexts as mentioned below.

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

huangapple
  • 本文由 发表于 2023年1月9日 17:45:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定