Sam*_*Sam 5 bash shell gitlab-ci
我有这个代码片段。它给了我语法错误:意外的文件结尾如果我将其复制到 .sh 文件中并在终端中运行,它就可以工作。
before_script:
- sbt sbtVersion
- for file in ./pending/*.sql; do
file=$(basename "$file")
export str_opt="$(cat ./pending/"$file"|tr '\n' ' ')"
mv ./pending/"$file" ./done/
done
Run Code Online (Sandbox Code Playgroud)
我哪里出错了?
do;
Run Code Online (Sandbox Code Playgroud)
没有;之后了do。去掉它。
gitlab-ci 中 yaml 的工作方式是将行连接成一长行,用换行符和行前导空格替换单个空格:
for file in ./pending/*.sql; do; file=$(basename "$file"); export str_opt="$(cat ./pending/"$file"|tr '\n' ' ')"; mv ./pending/"$file" ./done/; done
Run Code Online (Sandbox Code Playgroud)
这是无效的,因为;after do。
脚本如下:
before_script:
- sbt sbtVersion
- for file in ./pending/*.sql; do
file=$(basename "$file");
export str_opt="$(cat ./pending/"$file"|tr '\n' ' ')";
mv ./pending/"$file" ./done/;
done
Run Code Online (Sandbox Code Playgroud)
应该管用。