5

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:

.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.

In the gitlab docs it is mentioned, that I can use the bash syntax to supply variables, so $arg1 must the correct reference.

I use argparse in the script to get the cl arguments.

What is the correct way to call the variables in gitlab-ci.yml as the python script arguments?

1 Answer 1

8

Your variables is 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

More about yaml syntax

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.