如何在 AWS CodeBuild 的 buildspec 文件中运行 for 循环?

the*_*put 2 shell amazon-web-services aws-codebuild

我正在尝试使用以下方法运行 for 循环以遍历克隆代码中的多个文件夹

commands:
- folders=`ls`
- for value in ${folders}
- do
- some_code_here
- done
Run Code Online (Sandbox Code Playgroud)

另外,我尝试了不同的方法,例如

- for value in ${folders}; do
- some_code_here
- done
Run Code Online (Sandbox Code Playgroud)

但它们都不起作用。

Vik*_*yol 7

您应该将 for 循环编写为单行。由于 CodeBuild 将一个命令中的所有行合并在一起,因此您可以按如下方式以可读格式编写 for 循环:

- folders=`ls`
- for value in $folders;
   do
      echo $value;
   done
- echo "run the next command"
Run Code Online (Sandbox Code Playgroud)