这是我的 Bitbucket 管道的一部分:
npm_audit: &npm_audit
echo "Running npm audit..."
npm_audit_output=$(npm audit --audit-level=critical)
if [ $? -ne 0 ]; then
echo "Critical vulnerabilities found. They must be fixed manually:"
exit 1
fi
npm_audit_output=$(npm audit)
if [ $? -ne 0 ]; then
echo "Non-critical vulnerabilities found."
echo "$npm_audit_output"
echo "Attempting to fix..."
npm audit fix
else
echo "No vulnerabilities found."
fi
后来这样称呼:
- step:
...
script:
- *npm_audit
BB回归:
+ echo "Running npm audit..." npm_audit_output=$(npm audit --audit-level=critical) if [ $? -ne 0 ]; then echo "Critical vulnerabilities found. They must be fixed manually:" exit 1 fi npm_audit_output=$(npm audit) if [ $? -ne 0 ]; then echo "Non-critical vulnerabilities found." echo "$npm_audit_output" echo "Attempting to fix..." npm audit fix else echo "No vulnerabilities found." fi
bash: bashScript5261110360543614450.sh: line 5: syntax error near unexpected token `then'
为什么会出现语法错误? ShellCheck 为绿色
为什么会回显整个脚本而不是我要求的字符串?