我对Jenkins相当陌生,这是我第一次设置参数。我有多个帐户,我想运行相同的代码,以努力减少代码行。
我有5个帐户,它们在URL中使用相同的约定:
export PROFILE=account_oneexport PATH="http://account_one/this-is-just-an-example/stack-overflow"虽然1个账户不遵循本公约:
export PROFILE=account_twoexport PATH="http://second_account/this-is-just-an-example/stack-overflow"无论如何,我已经创建了一个名为“account”的多行字符串参数,并为值输入了所有5个帐户名。这就是我现在想做的:
if [ "${account}" = ???]
then
export PROFILE=${account}
export PATH="http://${account}/this-is-just-an-example/stack-overflow"
python3 run_code.py
elif [ "${account}" = "account_two" ]
export PROFILE="account_two"
export PATH="http://second_account/this-is-just-an-example/stack-overflow"
python3 run_code.py
fi首先,我想确保我做得对,因为我以前从未在Jenkins使用过任何参数化。
其次,我也不熟悉Bash,所以我不确定这里的语法。
最后,这是一个更多的编程问题,我不知道第一个if语句的内容。我尝试的是将if语句中的aws_account设置为多行字符串Param中的每个值。例如:
if [ "${account}" = "account_one"] || [ "${account}" = "account_three"]尽管每个帐户都有不同的名称,并且需要一个不同的路径,也就是说,account _one的路径是"http://account_one/this-is-just-an-example/stack-overflow“,所以我不希望account_three有路径"http://account_one/this-is-just-an-example/stack-overflow”。
我知道我的理解参差不齐,但詹金斯没有最好的例子,大多数都是互联网上没有答案的问题。请帮帮忙。
编辑:我创建了两个多行字符串参数,一个用于遵循文件格式的帐户,一个用于不遵循文件格式的帐户。我决定对每个帐户使用for循环:
for i in "${account[@]}"; do
export PROFILE=${i}
export PATH="http://${i}/this-is-just-an-example/stack-overflow"
python3 run_code.py
done
for i in "${account_other[@]}"; do
export PROFILE=${i}
export PATH="http://${i}/this-is-just-an-example/stack-overflow"
python3 run_code.py
done这是正确的吗?
发布于 2020-02-11 22:27:38
您可以使用单个多行字符串参数。让我们假设您已经将值account_one通过account_six分配给名为aws_accounts的多行字符串参数。
echo "${aws_accounts}"
account_one
account_two
account_three
account_four
account_five
account_six然后,可以在if-else循环中使用一个for语句来设置您的环境。
for account in "${aws_accounts}"; do
export PROFILE=${account}
if [ "${account}" = 'account_two' ]; then
export PATH="http://second_account/this-is-just-an-example/stack-overflow"
else
export PATH="http://${account}/this-is-just-an-example/stack-overflow"
fi
python3 run_code.py
donehttps://stackoverflow.com/questions/60177503
复制相似问题