4

I have the following gitab-ci.yml file:

stages:
  - tests

.test: &test_job
    image:
      name: test.com/test:latest
      entrypoint: [""]
    script:
    - py.test /test  -v $EXTRA_OPTIONS 

testing:
  variables:
    EXTRA_OPTIONS: -m "not slow"
  <<: *test_job
  stage: tests

I would like to pass option to run pytest like:
py.test /tests -v -m "not slow"
to avoid running slow tests, but gitlab is trying to escape quotes.
I've got something like: py.test /tests -v -m '"not\' 'slow"'

is it possible to create a variable that would be inlined without escaping?
All I found it's this link but it does not help.

Laser
  • 6,652
  • 8
  • 54
  • 85
  • AFAIK CI variables will always be escaped, and even worse: https://gitlab.com/gitlab-org/gitlab-ce/issues/27436 – djuarezg Jan 14 '19 at 12:50

1 Answers1

3

First of all, to avoid whitespace escaping in the variable, use single quotes:

variables:
    EXTRA_OPTIONS: -m 'not slow'

To apply the variable, you have two options:

  1. Use addopts combined with -o. addopts is an inifile key that enables you to persist command line args in pytest.ini. The -o/--override-ini arg allows one to override an inifile value, including addopts. The combination of both is a nifty trick to pass command line args via environment variables:

    script:
      - pytest -v -o "addopts=$EXTRA_OPTIONS" /test
    
  2. Use eval:

    script:
      - eval pytest -v "$EXTRA_OPTIONS" /test
    

    However, you need to be very careful when using eval; see Why should eval be avoided in Bash, and what should I use instead? . I would thus prefer the first option.

hoefling
  • 59,418
  • 12
  • 147
  • 194