Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate Eslint with jenkins?

Tags:

eslint

How can I integrate ESLint with Jenkins?

like image 268
sivaramanjaneyulu Avatar asked Aug 17 '15 05:08

sivaramanjaneyulu


People also ask

What is lint in Jenkins?

Command-line Pipeline Linter Jenkins can validate, or "lint", a Declarative Pipeline from the command line before actually running it. This can be done using a Jenkins CLI command or by making an HTTP POST request with appropriate parameters. We recommended using the SSH interface to run the linter.

What is checkstyle in Jenkins?

Jenkins simply reads the checkstyle report after it was run in the course of a build, and is extraneous to the question. To configure checkstyle, you want to modify or create checkstyle. xml (the location is configurable via method based your choice of build automation tool, such as maven or gradle.


1 Answers

You need to export your ESLint report into an xml file and use any of the violation/lint reporter plugins that jenkins has available like Checkstyle, Warnings or Violations plugins.

For ESLint I personally prefer using the Checkstyle plugin in Jenkins.

So the way you could export your eslint reports into Jenkins is by doing the following:

  1. From your Jenkins job's configuration screen, add a Build step of "Execute Shell"
  2. Add the following command into it: eslint -c config.eslintrc -f checkstyle apps/**/* > eslint.xml (replace apps/**/* to the path of your app files)
  3. Add a Post Build Action of "Publish Checkstyle analysis results" and input the path where your "eslint.xml" file got exported. (This is assuming you have installed the Checkstyle plugin in Jenkins)

Then, when you execute the job you will be able to see the ESLint report against the files it got executed.


Understanding what I have done with:

eslint -c config.eslintrc -f checkstyle apps/**/* > eslint.xml

  • -c config.eslintrc this point into the .eslintrc configuration file and uses whatever we specify there to use. (Please see above ESLint link I've provided)
  • -f checkstyle this will specify eslint what format it should use on the report, please see the available formats in this link
  • apps/**/* this is the path of the files you would like for eslint to check (**/* is the pattern for any files and folder)
  • > filename this is the export cli arg where the results are going to be stored each time the build is run

enter image description here

enter image description here

enter image description here

UPDATE:

With the latest version of ESLint you can export the output into whatever file you'd like with the following command line argument:

-o your_file.file_format

Please refer to their documentation

NOTE:

In the case that the invocation to eslint has errors, the command will return a value of 1, and the build will be marked as failed, which is not necessarily wanted. To avoid this, append the following: || true

like image 107
Carlos Melo Avatar answered Sep 22 '22 13:09

Carlos Melo