bash Gitlab-ci:如何使用 cl 参数运行 python 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46526769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gitlab-ci: how to run python script with cl arguments
提问by
I want to run a python script, which expects cl arguments, before the actual build, so I added the following piece in .gitlab-ci.yml:
我想在实际构建之前运行一个需要 cl 参数的 python 脚本,所以我在 .gitlab-ci.yml 中添加了以下部分:
.deploy_template: &template_name
variables:
- arg1: "https://some/url/"
- arg2: "https://another/url/"
- arg3: "https://one/more/url/"
script:
- python3 some/script/file.py $arg1 $arg2 $arg3
but I am getting the following error:
但我收到以下错误:
usage: file.py [-h] arg1 arg2 arg3
file.py: error: the following arguments are required: arg1 arg2 arg3
If the arguments are just strings (i.e. not variables), then it works fine, but it does not read the variables $arg1
etc.
如果参数只是字符串(即不是变量),那么它可以正常工作,但它不会读取变量$arg1
等。
In the gitlab docs it is mentioned, that I can use the bash syntax to supply variables, so $arg1
must the correct reference.
在 gitlab 文档中提到,我可以使用 bash 语法来提供变量,因此$arg1
必须正确引用。
I use argparsein the script to get the cl arguments.
我在脚本中使用argparse来获取 cl 参数。
What is the correct way to call the variables in gitlab-ci.yml as the python script arguments?
将 gitlab-ci.yml 中的变量作为 python 脚本参数调用的正确方法是什么?
回答by Rafael
Your variablesis a list, but it requires a dictionary. Just remove the -
from it.
您的变量是一个列表,但它需要一个字典。只需-
从中删除。
.deploy_template: &template_name
variables:
arg1: "https://some/url/"
arg2: "https://another/url/"
arg3: "https://one/more/url/"
script:
- python3 some/script/file.py $arg1 $arg2 $arg3