我有一个包含机密的 Azure KeyVault,我们将其称为“test1”。
我有一个运行 2 个 bash 脚本的 Azure DevOps 发布管道。一个是内联的,另一个基于文件。
内联脚本没有输入参数,因为它可以在没有输入参数的情况下处理变量组(即 Azure Key Vault)中的变量(秘密)。
基于文件的脚本有一个输入,在 DevOps 方面是
$(test1)
。
对于内联脚本:
echo "1" $test1
echo "2" test1
echo "3" "$test1"
echo "4" $(test1)
echo "5" ${test1}
echo "6" "$(test1)"
echo "7" "${test1}"
对于基于文件的脚本:
test1=$1
echo "1" $test1
echo "2" test1
echo "3" "$test1"
echo "4" $(test1)
echo "5" ${test1}
echo "6" "$(test1)"
echo "7" "${test1}"
如您所见,两个脚本是相同的。
内联脚本的输出:
2024-01-26T09:45:29.0382744Z 1
2024-01-26T09:45:29.0384501Z 2 test1
2024-01-26T09:45:29.0385029Z 3
2024-01-26T09:45:29.0385401Z 4 ***
2024-01-26T09:45:29.0385658Z 5
2024-01-26T09:45:29.0385948Z 6 ***
2024-01-26T09:45:29.0386188Z 7
基于文件的脚本的输出:
2024-01-26T09:45:28.6888518Z 1 ***
2024-01-26T09:45:28.6890152Z 2 test1
2024-01-26T09:45:28.6890863Z 3 ***
2024-01-26T09:45:28.7077227Z /d/a/r1/a/_secret/echo.sh: line 6: test1: command not found
2024-01-26T09:45:28.7104148Z 4
2024-01-26T09:45:28.7113476Z 5 ***
2024-01-26T09:45:28.7278287Z /d/a/r1/a/_secret/echo.sh: line 8: test1: command not found
2024-01-26T09:45:28.7287815Z 6
2024-01-26T09:45:28.7289441Z 7 ***
$(VARIABLE)
占位符。您应该使用环境变量:
批处理脚本:%VARIABLE_NAME%基于文件的脚本的输出:
2024-01-26T09:45:28.6888518Z 1 ***
2024-01-26T09:45:28.6890152Z 2 测试1
2024-01-26T09:45:28.6890863Z 3 ***
2024-01-26T09:45:28.7077227Z /d/a/r1/a/_secret/echo.sh:第6行:test1:找不到命令
设置秘密变量查看此文档了解如何使用秘密变量: