Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

How to integrate Eslint with jenkins?

I am trying to integrate Eslint with jenkins, but i didn't found any links in google, could you please help me for this.

Awaiting for your favorable response.

Thanks, Siva ramanjaneyulu vegi

question from:https://stackoverflow.com/questions/32043227/how-to-integrate-eslint-with-jenkins

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...