1

I have the following setup

  • jenkins runs in a docker container
  • in a sibling docker container I run a private npm registry
  • I use the Docker Pipeline Plugin and a Jenkinsfile to build a typescript library (with a node docker container)
  • I want to publish that library to that private registry to be able to use it in other build jobs

The problem is, as the registry runs on a port on the host it can't be reached from the docker in docker container that the Build Script spawns to build the lib. I find no info about how I can do something like --net="host" (from docker run) inside the jenkinsfile. I guess that would work?!

Any idea how I can improve the setup to build via a node docker container but be able to publish to the registry?

andymel
  • 4,538
  • 2
  • 23
  • 35
  • We successfully use DNS for this: register `jenkins.internal.yourdomain.com` and `npm.internal.yourdomain.com` and make jenkins publish to `npm.internal.yourdomain.com `. – MaratC Jun 30 '20 at 13:47

1 Answers1

5

I fixed it by connecting all three containers (jenkins, npm-registry and the container spawned for the build) to the same custom docker network.

As I configure the whole Jenkins server with Ansible I added following to the ansible script:

  • I create a docker network "Jenkins_network"
  • I connect the jenkins container to that network
  • I connect the npm-registry container to that network

In the jenkinsfile I added args '--net="jenkins_network"' to the docker block, which is now

pipeline {
  agent {
      docker {
          image 'node:lts-alpine'
          args  '--net="jenkins_network"'
      }
  }
  stages {
  ...
andymel
  • 4,538
  • 2
  • 23
  • 35