Reputation: 53
I wanted to know how to configure the correct .gitlab-ci.yml
file so that it'll automatically detect errors within the code that I've committed into my project.
for example I will create a new python file helloworld.py
:
print("hello world""
There is a clear error within the code above, and I want my .gitlab-ci.yml
to be able to test that code and make sure it will not pass.
How do I do this guys? I really appreciate any help on this.
Upvotes: 3
Views: 9541
Reputation: 5935
Try to execute the script in a linter:
.gitlab-ci.yml
:
image: ubuntu
hello-test:
script:
- apt-get update && apt-get install -y pylint3
- pylint3 helloworld.py
Or execute it in an interpreter directly:
.gitlab-ci.yml
:
image: ubuntu
hello-test:
script:
- apt-get update && apt-get install -y python3
- python3 helloworld.py
Upvotes: 4
Reputation: 295
Try to use following codes:
stages:
- build
PythonBuild:
stage: build
script:
- python helloworld.py
BTW, if you want to check all python files, you can add a shell script to help you do this.
bash.sh
#! bin/sh
for n in `find . -name "*.py"`
do
python $n
done
then edit .gitlab-ci.yml as following:
stages:
- build
PythonBuild:
stage: build
script:
- bash build.sh
: remeber to push build.bash to root path of your gitlab repository with .gitlab-ci.yml.
Upvotes: 1