Jenkins Docker static agent node build process

Jenkins Docker static agent node build process

A static node is fixed on a machine and is started through some fixed commands. A dynamic node has multiple tasks and can help you create multiple agents to run. Unlike static nodes, if multiple tasks come, they will wait in the task queue and then perform the build. This is the difference between static and dynamic.

The static node can be started by using the java -jar command.

1. Static Node Practice

First, create a jnlp type agent in Jenkins and obtain the authentication and key information required for the connection.

There are many parameters after the jar -jar command, which are used regardless of whether you are configuring dynamic nodes or static nodes.

java -jar agent.jar -jnlpUrl http://192.168.1.200:8080/computer/buildtest01/jenkins-agent.jnlp -secret 047a2627be5ee128c1a93f281051acc7bbbbd5221dcb56ae9fa408a494e72c2f -workDir "/home/jenkins"

1.1 Docker static node

Start the image and pass the authentication parameters. (Using docker actually means using an image, running an agent in the image, and then passing these parameters into it)

Download the agent.jar package on the virtual machine and execute these commands manually.

Start the node in the command line java -jar agent.jar -jnlpUrl http://139.198.166.235:8080/computer/build%2D02/jenkins-agent.jnlp -secret 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba -workDir "/var/jenkins"
Run from agent command line, with the secret stored in a file:
 
echo 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba > secret-file
java -jar agent.jar -jnlpUrl http://139.198.166.235:8080/computer/build%2D02/jenkins-agent.jnlp -secret @secret-file -workDir "/var/jenkins"

If it is in Docker, you need to find an agent image: inbound-agent image: Docker Hub

## test

[root@jenkins-agent ~]# docker run --init jenkins/inbound-agent -url http://139.198.166.235:8080 -workDir=/home/jenkins 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba build-02
 
 
 
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: build-02
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Oct 28, 2021 2:19:25 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 4.11
Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /home/jenkins/remoting as a remoting work directory
Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to /home/jenkins/remoting
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://139.198.166.235:8080/]
Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve
INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Agent discovery successful
  Agent address: 139.198.166.235
  Agent port: 50000
  Identity: 67:e8:d2:73:d1:cf:01:f6:6c:a4:cb:b3:0f:25:8c:3d
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to 139.198.166.235:50000
Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Trying protocol: JNLP4-connect
Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.protocol.impl.BIONetworkLayer$Reader run
INFO: Waiting for ProtocolStack to start.
Oct 28, 2021 2:19:26 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Remote identity confirmed: 67:e8:d2:73:d1:cf:01:f6:6c:a4:cb:b3:0f:25:8c:3d
Oct 28, 2021 2:19:26 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connected 

## Run

[root@jenkins-agent ~]# docker run -itd --name build-02 jenkins/inbound-agent -url http://139.198.166.235:8080 -workDir=/home/jenkins 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba build-02
bd2500223dabb45ff41c234a8871651f93b38264458c4d2bed40f821577b8944
 
 
[root@jenkins-agent ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd2500223dab jenkins/inbound-agent "/usr/local/bin/jenk?? 18 seconds ago Up 18 seconds build-02

It should be noted here that there is nothing in the static docker agent, such as the build tool.

[root@jenkins-agent ~]# docker exec -it build-02 bash
jenkins@bd2500223dab:~$ mvn
bash: mvn: command not found

So the solution is to use the agent image as the base image, put the build tool into it, then you can use it, or mount the tool into it.

docker run -itd --name build-02 \
-v /usr/local/apache-maven-3.8.1:/home/jenkins/apache-maven-3.8.1 \
jenkins/inbound-agent -url http://139.198.166.235:8080 -workDir=/home/jenkins 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba build-02

jenkins@2a682b01263b:~$ /home/jenkins/apache-maven-3.8.1/bin/mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /home/jenkins/apache-maven-3.8.1
Java version: 11.0.12, vendor: Eclipse Foundation, runtime: /opt/java/openjdk
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"

Similarly, use the docker command to mount it.

This is the end of this article about building a Jenkins Docker static agent node. For more information about Jenkins Docker nodes, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker Gitlab+Jenkins+Harbor builds a persistent platform operation
  • Automatically build and deploy using Docker+Jenkins
  • When setting up Jenkins in Docker environment, the console log shows garbled Chinese characters when building tasks
  • Detailed explanation of setting up Jenkins build environment under Docker
  • Jenkins builds Docker image example

<<:  Share 16 burning flame effect English fonts treasure trove

>>:  Pay attention to the order of TRouBLe when writing shorthand properties in CSS (to avoid pitfalls)

Recommend

Detailed explanation of the practical use of HTML table layout

When is the table used? Nowadays, tables are gene...

Native JS to achieve directory scrolling effects

Here is a text scrolling effect implemented with ...

A brief discussion on VUE uni-app's commonly used APIs

Table of contents 1. Routing and page jump 2. Int...

Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

1. Add the following dependencies in pom.xml <...

Vue implements the product tab of the product details page function

This article example shares the specific code of ...

How to hide and remove scroll bars in HTML

1. HTML tags with attributes XML/HTML CodeCopy co...

Detailed explanation of how to use the vue verification code component

This article example shares the specific implemen...

HTML Tutorial: Collection of commonly used HTML tags (6)

Related articles: Beginners learn some HTML tags ...

Summary of uncommon js operation operators

Table of contents 2. Comma operator 3. JavaScript...

js to realize the production method of carousel

This article shares the specific code for js to r...

A detailed introduction to setting up Jenkins on Tencent Cloud Server

Table of contents 1. Connect to Tencent Cloud Ser...

Analysis of pitfalls in rounding operation of ROUND function in MySQL

This article uses examples to illustrate the pitf...