问题
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.
回答1:
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:
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, includingaddopts
. The combination of both is a nifty trick to pass command line args via environment variables:script: - pytest -v -o "addopts=$EXTRA_OPTIONS" /test
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.
来源:https://stackoverflow.com/questions/54181673/gitlab-ci-variable-option-with-quotes