Analyze Javascript code (React Native, Typescript, Nodejs etc) with Sonarqube and Jenkins (or local)

Tiempo de lectura: 3 minutos
Today we’re going to see how to analyze JavaScript, React Native, or Node.js code using SonarQube and Jenkins.

Install Node.js with Jenkins

If we want to execute a project with JavaScript, we need to install Node.js on the machine where the scan is performed. In this case, on Jenkins.

To do that, we install the Node.js plugin:

To install it automatically, we need to go to the global configuration and select Node.js:

Choose the version and select the installation from npm:

It is recommended to use Node 16 or 18 due to the warning displayed in SonarQube:

To apply the installation and download, create a new Job and go to Build Steps and select Execute NodeJS script. This way, Node.js will be downloaded automatically on the machine.

Now click on Save and Build Now:

It will start installing Node.js and display the installation path:

Once installed, we need to go to the project’s configuration file sonar-project.properties and add the path to the Jenkins Node.js executable, followed by /bin/node.

sonar.nodejs.executable=/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS/bin/node

For local Node.js installation:

If we’re not using the Jenkins plugin but running the scan on a local machine with Node.js installed, we indicate the installation directory:

 /usr/bin/node

Now we can execute React Native or JavaScript projects:

And that’s it! You have successfully installed SonarQube with Docker and set up code analysis for your projects. By integrating SonarQube with Jenkins and configuring the necessary plugins and settings, you can ensure the quality and maintainability of your codebase.

Remember to regularly run the SonarQube scan on your projects to identify potential issues and vulnerabilities, and take the necessary steps to address them.

Happy coding and happy analyzing!


If you found this guide helpful, please consider sharing it with others who might benefit from it. Let’s spread the knowledge and help improve code quality across the development community!

Thank you for reading!

PIPE

Leave a Comment