Jenkins|Jenkins Docker静态agent节点的构建过程

静态节点就是固定的在一台机器上面,通过一些固定的命令将其启动起来,动态节点就是来了多个任务,可以帮你创建多个agent去跑。而不像静态节点来了多个任务,那么就会等待这个任务队列,然后进行这个构建。这就是静态和动态的区别。
静态节点就是通过java -jar这条命令去启动起来就可以了。
1. 静态节点实践 首先,在Jenkins 中创建一个jnlp类型的agent, 拿到连接所需要的认证和秘钥信息。
jar -jar这条命令后面有很多的参数,不管是配置动态节点还是静态节点,这些参数都会用到。

java -jar agent.jar -jnlpUrl http://192.168.1.200:8080/computer/buildtest01/jenkins-agent.jnlp -secret 047a2627be5ee128c1a93f281051acc7bbbbd5221dcb56ae9fa408a494e72c2f -workDir "/home/jenkins"
1.1 Docker静态节点
启动镜像,传递认证参数。(使用docker的话其实就是使用一个镜像,镜像里面运行了一个agent,然后将这些参数传递进去)
Jenkins|Jenkins Docker静态agent节点的构建过程
文章图片

Jenkins|Jenkins Docker静态agent节点的构建过程
文章图片

在虚拟机上面下载agent.jar包然后手动执行这些命令就可以了
在命令行中启动节点 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-filejava -jar agent.jar -jnlpUrl http://139.198.166.235:8080/computer/build%2D02/jenkins-agent.jnlp -secret @secret-file -workDir "/var/jenkins"

如果是在docker里面就需要找一个agent镜像:inbound-agent镜像 : Docker Hub
## 测试
[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 createEngineINFO: Setting up agent: build-02Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener INFO: Jenkins agent is running in headless mode.Oct 28, 2021 2:19:25 AM hudson.remoting.Engine startEngineINFO: Using Remoting version: 4.11Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDirINFO: Using /home/jenkins/remoting as a remoting work directoryOct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.WorkDirManager setupLoggingINFO: Both error and output logs will be printed to /home/jenkins/remotingOct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Locating server among [http://139.198.166.235:8080/]Oct 28, 2021 2:19:25 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolveINFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Agent discovery successfulAgent address: 139.198.166.235Agent port:50000Identity:67:e8:d2:73:d1:cf:01:f6:6c:a4:cb:b3:0f:25:8c:3dOct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: HandshakingOct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Connecting to 139.198.166.235:50000Oct 28, 2021 2:19:25 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Trying protocol: JNLP4-connectOct 28, 2021 2:19:25 AM org.jenkinsci.remoting.protocol.impl.BIONetworkLayer$Reader runINFO: Waiting for ProtocolStack to start.Oct 28, 2021 2:19:26 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Remote identity confirmed: 67:e8:d2:73:d1:cf:01:f6:6c:a4:cb:b3:0f:25:8c:3dOct 28, 2021 2:19:26 AM hudson.remoting.jnlp.Main$CuiListener statusINFO: Connected

Jenkins|Jenkins Docker静态agent节点的构建过程
文章图片

【Jenkins|Jenkins Docker静态agent节点的构建过程】## 运行
[root@jenkins-agent ~]# docker run -itd --name build-02 jenkins/inbound-agent -url http://139.198.166.235:8080 -workDir=/home/jenkins 942d7e769a43f65388751ee954af20e90fa0c5f8bdb19e0584db4cc61adab8ba build-02bd2500223dabb45ff41c234a8871651f93b38264458c4d2bed40f821577b8944 [root@jenkins-agent ~]# docker psCONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMESbd2500223dabjenkins/inbound-agent"/usr/local/bin/jenk??18 seconds agoUp 18 secondsbuild-02

这里需要注意,docker的静态agent里面什么都没有,比如构建工具是没有的
[root@jenkins-agent ~]# docker exec -it build-02 bashjenkins@bd2500223dab:~$ mvnbash: mvn: command not found

所以解决办法是将agent镜像作为基础镜像,将构建工具打进去,那么你就可以使用了,或者将工具挂载进去。
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-02jenkins@2a682b01263b:~$ /home/jenkins/apache-maven-3.8.1/bin/mvn -vApache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)Maven home: /home/jenkins/apache-maven-3.8.1Java version: 11.0.12, vendor: Eclipse Foundation, runtime: /opt/java/openjdkDefault locale: en, platform encoding: UTF-8OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"

同理使用docker命令也一样挂载进去。
到此这篇关于Jenkins Docker静态agent节点的构建的文章就介绍到这了,更多相关Jenkins Docker 节点内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

    推荐阅读