I don't understand why Job finished with exit code 1 in gitlab CI. If I don't use flake8 (f.ex run script line echo "hello world" > $FOLDER_NAME/my_test.txt
) all good.
But I see that flake8 found errors in directory:
...
$ mkdir -p $FOLDER_NAME
$ flake8 --max-line-length=120 --ignore=W605,W504 --tee --output-file=$FOLDER_NAME/$LOG_NAME $CHECKING_FOLDER
./framework/tests/test_5_helper.py:30:30: W292 no newline at end of file
./framework/tests/test_1_start.py:2:1: F401 'pprint.pprint' imported but unused
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1
yml-file:
stages:
- check
pep8_check:
stage: check
image: python:3.8-alpine
variables:
FOLDER_NAME: 'logs'
LOG_NAME: 'linter.log'
CHECKING_FOLDER: './framework/tests'
when: always
before_script:
- python -m pip install --upgrade pip
- pip install flake8
- export
- mkdir -p $FOLDER_NAME
script:
- flake8 --max-line-length=120 --ignore=W605,W504 --tee --output-file=$FOLDER_NAME/$LOG_NAME $CHECKING_FOLDER
artifacts:
expire_in: 7 days
paths:
- $FOLDER_NAME/
Flake8 finds 2 errors so exits with 1, this makes the GitLab pipeline fail.
You have a few options:
flake8
may find, then you can just add the parameter --exit-zero
, this will make flake8
exit with 0
which makes the GitLab pipeline successful./framework/tests/test_5_helper.py:30:30: W292 no newline at end of file
./framework/tests/test_1_start.py:2:1: F401 'pprint.pprint' imported but unused
then you just have to add those to the ignore list like you did for others:
change this --ignore=W605,W504
to this --ignore=W605,W504,W292,F401
flake8
stops flagging those lines when parsing your source codeIn any case reading the help with flake8 --help
may give some more ideas on how to tackle these corner cases depending on what you want to achieve.
Also see here the lists of error/warning/violation codes E***
, W***
, F***
: