📜 ⬆️ ⬇️

Jenkins + JsHint (JsLint) or look javaScript metrics on Jenkins

Hello. Got such a task, in principle, everything is clear from the title of the topic.
About how I achieved this, step by step, will be the next post.
If something goes wrong - criticism is welcome, it was a research assignment, so to speak, and before starting work on it I did not have a clue about this tool, why it was so ...
In the process of research, many questions were clarified.


The essence of the job in more detail.
It was necessary for the project on Jenkins-e to display a graph and a small statistic on the metrics of the JavaScript code from the project.
In this case, the prerequisite as an analysis of js-code was the use of only JsHint, then JsLint does not work.

The collection of information has begun, as I heard such a word for the first time. Jenkins has a huge plugin library and, accordingly, someone has already asked this question. So Jenkins-plugin was first searched.
The plugin was successfully found, but I could not screw it to the server.
Here is a link to the plugin, there is also information on how to fasten it.
http://www.boxuk.com/labs/jslint-jenkins-plugin/
')
Further search led me to nodeJs and its plugin (npm) jshint.
Next, step by step, what should be done in order to get code analysis using Jenkins on JSHint.

  1. Install nodejs

  2. Install jshint-npm:
    npm install -g jshint
    Documentation:
    https://npmjs.org/package/jshint

  3. To ignore unnecessary folders and files, create in the root folder of the project (where pom.xml lies) a file called
    .jshintignore
    for example, we want to ignore all files from the following src / main / webapp / resources / js / lib / directory
    then in the file .jshintignore and write
    src/main/webapp/resources/js/lib/

  4. The .jshintignore file can be configured using minimatch regular expressions.
    https://github.com/isaacs/minimatch

  5. Install Violation-Plugin for Jenkins, it supports (reads) various code metrics including jslint / jshint
    https://wiki.jenkins-ci.org/display/JENKINS/Violations

  6. After installing the plugin, re-launch Jenkins, go to the project configuration and find the “violations” checkbox there.
    We open it and see that it can already read the xml file with jslint code metrics.

  7. And finally, the most important team for which all these dances with a tambourine were started.
    This command is written in the configuration of the project as "run a shell command."
    jshint ./src/main/webapp/resources/js --jslint-reporter > ./target/jslint.xml
    we run the previously installed jshint-npm as a parameter; we transfer the folder with js files for analysis, while saying that we need to generate a report in the jslint style, since our violation-plugin can only read jslint-report. and successfully write everything to the file at the specified path.

  8. In the violation-plugin specify the path to our
    ./target/jslint.xml

  9. All is ready! You can run and enjoy the schedule and statistics.


I hope someone will come in handy.
I ask all newbies to me, I will try to write something regularly: j-web-dev.blogspot.com/
PS For the blog do not kick much, no one is born a professional. )

Source: https://habr.com/ru/post/160181/


All Articles