【问题标题】:Gitlab-ci: how to run python script with cl argumentsGitlab-ci:如何使用 cl 参数运行 python 脚本
【发布时间】:2018-03-13 14:22:10
【问题描述】:

我想在实际构建之前运行一个需要 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 脚本参数的正确方法是什么?

【问题讨论】:

    标签: python bash yaml command-line-arguments gitlab-ci


    【解决方案1】:

    您的变量 是一个列表,但它需要一个字典。只需从中删除-

    .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
    

    More about yaml syntax

    【讨论】:

      猜你喜欢
      • 2019-06-23
      • 1970-01-01
      • 2016-01-01
      • 2021-12-08
      • 1970-01-01
      • 2018-03-09
      • 2018-07-25
      • 1970-01-01
      相关资源
      最近更新 更多