[英]Executing python script using Jenkins parameterized pipeline
我已经使用 Jenkins 中的执行 shell 功能设置了 Jenkins 参数化作业来执行 python 脚本。 该作业具有以下参数:
user-name:字符串,order_area_name:逗号分隔的字符串,country_name:字符串,country_code:字符串,等等...
我的用例是拆分 order_area_name 并为每个 order_area_name 依次执行 python 脚本。 所以,我写了一个看起来像这样的脚本:
#!/bin/bash
export PYTHONHASHSEED=0
empty_string=""
parameters_list=""
IFS=","
#Checking every parameter if it is present or not
if [ "$user_name" != "$empty_string" ]
then
parameters_list=$parameters_list" --user "$user_name
fi
if [ "$country_code" != "$empty_string" ]
then
parameters_list=$parameters_list" --country_code "$country_code
fi
if [ "$country_category" != "$empty_string" ]
then
parameters_list=$parameters_list" --country_category "$country_category
fi
parameters_list=$parameters_list" --aws_access_key_id "$aws_access_key_id
parameters_list=$parameters_list" --aws_secret_access_key "$aws_secret_access_key
##Checking if the parameter is present then splitting the string and storing it into array
##Then for each order_area_name executing the python script in sequential manner
if [ "$order_area_names" != "$empty_string" ]
then
read -r -a order_area_name_array <<< "$order_area_names"
for order_area in "${order_area_name_array[@]}";
do
final_list=$parameters_list" --order_area_name "$order_area
echo $final_list
python3 ./main.py ${final_list}
done
fi
exit
我无法将值的final_list传递给 python 脚本,因此 Jenkins 作业失败。 如果我回显final_list ,我会看到这些值已正确初始化:
--user jay@abc.com --mqs_level Q2 --num_parallel_pipelines 13 --sns_topic 主题名 --ramp_up_time 45 --max_duration_for_task 30 --batch_size 35 --lead_store_db_schema 架构 --airflow_k8s_z344aws67y_name 气流-keyid_web-x12 aws_secret_access_key 12345678 --order_area_name 伦敦
错误看起来像这样:
main.py:错误:需要以下 arguments:--user、--sns_topic、--aws_access_key_id、--aws_secret_access_key 构建步骤“执行 shell”将构建标记为失败已完成:失败
我在很多地方搜索过这个,但没有得到任何具体的答案。 谁能帮我解决这个问题?
而不是像这样写我的命令:
python3./main.py ${final_list}
我用了这个,效果很好:
echo $final_list | bash
“final_list”变量具有需要执行的命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.