/ #jenkins #node 

Configuring Node js on Jenkins using docker

Jenkins is a devops tool for continuous intergration.

Install jenkins

Requirements for this tutorial :

  • Docker
  • Docker compose

We will user docker compose to configure jenkins docker container:

version: '3.5'

    image: 'jenkins/jenkins:lts'
    container_name: 'jenkins'
    restart: always
      - '8080:8080'
      - '50000:50000'
      - jenkins-data:/etc/gitlab
      - /var/run/docker.sock:/var/run/docker.sock

    name: jenkins-data

Then, run the command :

$ docker-compose up -d

Run Jenkins

Once you had run the docker compose file, test that your jenkins is running by opening this url on your browser http://localhost:8080

Install NodeJS Plugin

When jenkins is ready, go to “Manage Jenkins” => “Manage Plugins” and Install NodeJs Plugin and NPM Plugin.

Later, go to “Manage Jenkins” => “Global Tool configuration”, go down to NodeJS and choose the version you want to use. Dont forget to check the “automatic installation” checkbox.

Important: At this point, node and npm are not installed yet. In order to install them:

  • create a “Freestyle project”
  • In the project configuration page: Check the box “Provide Node & npm bin/ folder to PATH”, and choose the version of node you want.
  • In the project configuration page: In the “Build” part, click “a shell script” and add the command “node -v”
  • Run the project

If node is installed, the jenkins job will pass and you will see in the console output: “vXX.XX.XX”

Configuring NPMRC Optional

You can add your npm settings from jenkins. Go to “Manage Jenkins” => “Managed Files” => choose npmrc and set your configuration

Set A Variable environment

Previously, Nodejs have been installed. But, the installation was not global. In order to make nodejs accessible for all jobs, we should add an Environment Variable for the job runner. Go to “Manage Jenkins” => “Manage Nodes” => For all the nodes, add this environment :


Test your own code

Now that you have configured nodejs, create a new project with a jenkinsfile and run it.

Buy Me A Coffee

Omar Ghader

Fullstack web engineer and devops. Mobile web specialist