Windows/Linux (Docker) Deploy multiple Jenkins nodes on a single host

  • In the process of using Jenkins, manual input steps are added, which will block node running tasks.
  • Due to limited resources, many Jenkins nodes need to be mounted in one machine.
  • Jenkins node runs in Java mode.

Environment:

  • Windows10
  • Docker
  • Apline Linux
  • OpenJdk11

precondition

  • Select “Start proxy via Java Web” when creating Jenkins node
  • After the startup is complete, run the following command (only the path is different for Windows and Linux) :
  • The Windows startup command is as follows:
  • Java – jar agent. The jar – jnlpUrl http://192.168.0.1:8080/computer/XuXiaoCong-Windows/jenkins-agent.jnlp – secret 1234567890abcdefg -workDir “F:\Jenkins_nodes\XuXiaoCong-Windows”
  • The Linux startup command is as follows:
  • Java – jar agent. The jar – jnlpUrl http://192.168.0.1:8080/computer/XuXiaoCong-Linux/jenkins-agent.jnlp – secret 1234567890abcdefg -workDir “/var/jenkins”

Window Multiple nodes are deployed

  1. Since many nodes need to be mounted, using the.bat batch file requires launching multiple interfaces
  2. Jar is a download link in Jenkins node interface. Click download
  3. Create a batch command for each node named ‘< node name >.bat’
  4. Write the node startup command to “java-jar agent.jar-jnlpurl ******”.
  5. Place batch commands in the same folder as Agent.jar
  6. Double-click start, a CMD window will open (do not close, or the node will go offline)

Example: XuXiaoCong – Windows. Bat

Java - jar agent. The jar - jnlpUrl http://192.168.0.1:8080/computer/XuXiaoCong-Windows/jenkins-agent.jnlp - secret 1234567890abcdefg -workDir "F:\Jenkins_nodes\XuXiaoCong-Windows"Copy the code

Linux (Docker) deploys multiple nodes

  1. Make a Docker image
  2. Image generation container
FROM alpine
WORKDIR /jenkins
# apk mirror
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# add curl, git, openjdk11
RUN apk add --no-cache curl
RUN apk add --no-cache git
RUN apk add --no-cache openjdk11

# Add other runtime environments (Python as an example)
RUN apk add --no-cache build-base
RUN apk add --no-cache python3
RUN apk add --no-cache python3-dev
RUN apk add --no-cache py3-pip

The Agen. Jar path on the # Jenkins page (right click to copy the link)
RUNThe curl - o agent. The jar at http://192.168.0.1:8080/jnlpJars/agent.jar

# execute the node (statement copied from Jenkins node interface) (just execute CMD, rest comments)

# XuXiaoCong - Linux node
CMDJava - jar agent. The jar - jnlpUrl http://192.168.0.1:8080/computer/XuXiaoCong-Linux/jenkins-agent.jnlp - secret 1234567890abcdefg -workDir"/var/jenkins"
# docker build -t jenkins-node-xuxiaocong-linux .
# docker run -d --restart=always --name=jenkins-node-xuxiaocong-linux jenkins-node-xuxiaocong-linux

# XuXiaoCong - Linux - 1 nodes
# CMD Java - jar agent. The jar - jnlpUrl http://192.168.0.1:8080/computer/XuXiaoCong-Linux-1/jenkins-agent.jnlp - secret 1234567890abcdefg -workDir "/var/jenkins"
# docker build -t jenkins-node-xuxiaocong-linux-1 .
# docker run -d --restart=always --name=jenkins-node-xuxiaocong-linux-1 jenkins-node-xuxiaocong-linux-1
Copy the code
  • Create an image in Windows
CD < file path > docker build -t Jenkins -node-< node name >Copy the code
  • Generated container
Docker run -d --restart=always --name=jenkins-node-< node name >Copy the code

Reference Documents:

Docs.docker.com/get-started wiki.alpinelinux.org/wiki/Main_P… www.cnblogs.com/jackadam/p/…