yaml - GitHub Actions 将变量列表传递给 shell 脚本

标签 yaml github-actions

我想使用 GitHub Actions 调用带有目录列表的 shell 脚本。 (本质上等同于将 Ansible vars 列表传递给 shell 脚本)

我真的不知道怎么做,这甚至可能吗?这是我到目前为止所拥有的,如何改进它?

name: CI

on:
  push:
    branches:
      - master

    tags:
      - v*

  pull_request:

jobs:
  run-script:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2

      - name: Run script on targets
        run: ./.github/workflows/script.sh {{ targets }}
        env:
          targets:
            - FolderA/SubfolderA/
            - FolderB/SubfolderB/

最佳答案

今天我能够使用以下 YAML(截断的)执行此操作:

...
with:
  targets: |
    FolderA/SubfolderA
    FolderB/SubfolderB

实际的 GitHub Action 将其作为参数传递,如下所示:

runs:
  using: docker
  image: Dockerfile
  args:
    - "${{ inputs.targets }}"

它所做的只是将参数作为嵌入了换行符的字符串发送,然后可以通过以下 shell 代码以类似于 POSIX 兼容的方式对它进行迭代:

#!/bin/sh -l

targets="${1}"

for target in $targets
do
  echo "Proof that this code works: $target"
done

如果我正确理解问题,它应该能够完成您想要的任务。如果您的用例需要,您始终可以在循环中运行类似 sh ./script.sh $target 的东西。

关于yaml - GitHub Actions 将变量列表传递给 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65345432/

相关文章:

javascript - 如何从 application.js 在 rails 中访问 yml 文件?

javascript - 如何查看 serverless.yml 中解析的变量?

javascript - 如何在 JS 文件中使用 GitHub secret 环境变量?

Github 操作 : Required status check doesn't run due to files in paths not changed

docker - 如何使用 Github Actions 登录 Docker 注册表

yaml - 使用 PyYAML.dump() 生成 anchor ?

java - 使用 dropwizard 时 config.yml 为 "maxFileSize must be specified"

java - 使 YamlBeans 忽略特定的类成员

docker - 我可以在 GitHub Actions 工作流程中引用 Dockerfile 而不是图像吗?

docker - 创建引用 Github 包上的图像的 Github Docker 容器操作