I would like to prevent TODO comments (or other problematic strings) from being checked in with a gitlab CI test rule. I added the last line here:
.job_template: &template_test
image: python:3.6-stretch
tags:
- python
# ...
stages:
- test
test:
<<: *template_test
stage: test
script:
- flake8 *.py
- ! grep TODO *.py
But when I look at the output of the runner, it fails:
$ flake8 *.py
$ grep TODO *.py
ERROR: Job failed: exit code 1
It seems like Gitlab swallowed the exclamation mark !
, used in the shell to negate the return value of grep.
Lint, or a linter, is a static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs. The term originates from a Unix utility that examined C language source code.
These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.
The CI lint tool checks the syntax of GitLab CI/CD configuration, including configuration added with the includes keyword. To check CI/CD configuration with the CI lint tool: On the top bar, select Main menu > Projects and find your project. On the left sidebar, select CI/CD > Pipelines.
A line with the exclamation mark (! grep ...
) at the beginning must be quoted. However, even this ('! grep ...'
) will not work here, return code will always be zero. I got the solution from https://stackoverflow.com/a/31549913/491884, a subshell must be started because GitLab CI starts the shell with set -e
. This should work and is reasonably short:
script:
...
- (! grep TODO *.py)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With