Goal
- Build project
- Extract information from
maven
build results
- Post comment to commit
Prepare project
Private token
First we have to add some users’ private_token
as secret variable
in CI project’s settings.
I’ve set USER_PRIVATE_TOKEN
secret with value of private_token
for
some technical user - lets call it MvnBot
.
Remember that all users with role master
have access to project’s
configuration.
Now it is possible to generate comment using curl
.
Build project
So now we have to build project and generate all the information we need during the build.
Let’s configure build in .gitlab-ci.yml
by setting script
parameter like:
Maven goals should be set in pom.xml for all builds. But here I want to show all changes.
./add_comments.sh
refers to our final script that will add comment in project.
Let’s try to extract some data from maven build and attach them as comments to commit.
Checkstyle
Extract the number of style errors in code:
Pmd
Extract the number of violations found in project:
Cobertura
Extract code coverage level:
Find Bugs
Extract the number of bugs found in project:
So below is simple script I’ve written to attach some data from build result
to commit as comment. Please treat it as excercise!
I’ve put this code into add_comments.sh
file directly in project’s directory.
Remember that this file has to have execution permissions in git repository!
Final word
This is very easy way of adding information from build to commits in Gitlab repository.