GitHub 工作流程输入参数的下拉列表

vik*_*nag 43 github-api github-actions building-github-actions

我想为我的 GitHub 操作输入参数创建一个下拉列表。这应该有助于从下拉列表中选择一个值,就像选项如何选择分支一样。

Jon*_*ldt 92

使用 时workflow_dispatch现在可以choice,booleanenvironment输入,而不仅仅是字符串。choice是一个下拉菜单,boolean是一个复选框,environment类似于choice但会自动填充存储库设置中配置的所有环境。

以下是使用新类型的示例工作流程:

name: CI

on:
  workflow_dispatch:
    inputs:
      environment:
        type: environment
        description: Select the environment
      boolean:
        type: boolean
        description: True or False
      choice:
        type: choice
        description: Make a choice
        options:
        - foo
        - bar
        - baz
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: greet
        run: | 
          echo "environment is ${{ github.event.inputs.environment }} / ${{ inputs.environment }}"
          echo "boolean is ${{ github.event.inputs.boolean }}" / ${{ inputs.boolean }} 
          echo "choice is ${{ github.event.inputs.choice }}" / ${{ inputs.choice }}
Run Code Online (Sandbox Code Playgroud)

请注意,现在可以使用context直接访问inputs输入,而不是使用github.event.inputs.

工作流程示例

  • 以编程方式填充选择或以其他方式在其中一个步骤中输入怎么样? (2认同)
  • `inputs.inputname` 和不是 `github.event.inputs.inputname` 并不总是相同。例如,假设分派工作流调用一个操作。工作流程和操作具有不同的输入。当您在 aciton 中引用 `inputs.inputname` 和 `github.event.inputs.inputname` 时。`inputs.inputname` 将是操作的输入,而 `github.event.inputs.inputname` 将是工作流的输入。 (2认同)