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,然后将这些参数传递进去)
在虚拟机上面下载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-file java -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 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
## 运行
[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
这里需要注意,docker的静态agent里面什么都没有,比如构建工具是没有的
[root@jenkins-agent ~]# docker exec -it build-02 bash jenkins@bd2500223dab:~$ mvn bash: 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-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"
同理使用docker命令也一样挂载进去。
到此这篇关于jenkins docker静态agent节点的构建的文章就介绍到这了,更多相关jenkins docker 节点内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!