我想在实际构建之前运行一个需要 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
但我收到以下错误:
usage: file.py [-h] arg1 arg2 arg3
file.py: error: the following arguments are required: arg1 arg2 arg3
如果参数只是字符串(即不是变量),那么它工作正常,但它不会读取变量 $arg1
等。
在 gitlab 文档中提到,我可以使用 bash 语法来提供变量,因此 $arg1
必须是正确的引用。
我使用 argparse在脚本中获取 cl 参数。
调用 gitlab-ci.yml 中的变量作为 python 脚本参数的正确方法是什么?
最佳答案
您的变量 是一个列表,但它需要一个字典。只需从中删除 -
。
.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
关于python - Gitlab-ci:如何使用 cl 参数运行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46526769/