Configuring Node js on Jenkins using docker

August 22, 2018 · jenkins, node, nodejs, npmrc, docker, jenkins_nodejs

Jenkins is a devops tool for continuous intergration.

Install jenkins

Requirements for this tutorial :

We will user docker compose to configure jenkins docker container:

version: '3.5'

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

volumes:
  jenkins-data:
    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:

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 :

PATH=$PATH:/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin

Test your own code

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

Building something like this in production?

I help teams turn setups like this into reliable, monitored infrastructure.

Get a free consulting call

Get my monitoring stack checklist

The exact checklist I use when setting up observability for a new team. No spam, unsubscribe anytime.