BlimBlam
BlimBlam

Reputation: 366

Publishing Static Code Metric reports in Jenkins using declarative pipeline(Jenkinsfile)

I am building a simple CI pipeline for my python code in Jenkins using Jenkinsfile, which basically does the following things:

  1. Creating test environment and installing dependencies.
  2. Running static code metrics:
    • various raw metrics : SLOC, comment lines, blank lines, Cyclomatic Complexity, the Maintainability Index etc.
    • tests coverage reports using coverage
    • errors and style check using pylint
  3. Testing pulled source code (Unit testing)

So lets say i have this stage for example, for "Static code metrics":

...
        stage('Static code metrics') {
            steps {
                echo "Raw metrics"
                sh  ''' radon raw --json my_python_repo/ > raw_report.json
                        radon cc --json my_python_repo/ > cc_report.json
                        radon mi --json my_python_repo/ > mi_report.json
                        //TODO: add conversion and HTML publisher step
                    '''
            }
        }

...

As you see above, the reports are saved in .json format. I need to figure out a way to publish these reports in a pretty visual way on Jenkins dashboard. One of the steps is to convert the .json files to HTML and then use HTML publisher plugin to publish reports but i don't know what tool to use. If there is way to solve this or any other way to publish these reports on jenkins dashboard, please provide the solution.

Lets say content of mi_report.json is:

 {"my_python_repo/code.py": {"mi": 16.42950884051172, "rank": "B"}, "my_python_repo/test.py": {"mi": 33.532817596089814, "rank": "A"}}

Upvotes: 1

Views: 826

Answers (1)

whitediver
whitediver

Reputation: 468

There is no Jenkins-ready tool to publish custom JSON as HTML. But you can use warnings plugin to publish your metrics in the Jenkins way. Here small instruction on how to configure Jenkins to parse radon reports.

Upvotes: 2

Related Questions