外部Jenkins調用容器中Slave配置實踐
阿新 • • 發佈:2018-12-20
style post paas color spa chmod info 外部 aps
1.Jenkins配置
實現動態生成的Slave節點並調用,解決構建項目出現slave節點任務堵塞或者是slave宕機問題。容器平臺采用openshift。
參考配置文檔:https://blog.csdn.net/felix_yujing/article/details/78725142
參考配置文檔:https://www.imooc.com/article/35851
1.1 jenkins jnlp配置
1.2.Kubernetes配置
名稱: 默認使用Kubernetes即可
Kubernetes地址: 填寫paas平臺地址
Kubernetes證書: 填寫paas平臺中名稱空間中的jenkins的secret中的token,選擇ca.crt內容。
Kubernetes命名空間: 填寫jenkins的項目空間 。
憑據: 通證書一樣的獲取方式,只不過獲取的不再試ca.crt內容,而是token。復制創建jenkins的憑據,憑據選擇secret text格式。
2.Jenkins Slave配置
2.1 Dockerfile
鏡像倉庫:https://hub.docker.com/search/?q=openshift%20jenkins%20slave%20&type=image
FROM registry.it.com/openshift/jenkins-jnlp-slave:latest USER root RUN rm -fr /usr/share/jenkins/slave.jarRUN rm -fr /usr/local/bin/jenkins-slave COPY agent.jar /usr/share/jenkins/agent.jar COPY jenkins-slave /usr/local/bin/jenkins-slave RUN chmod 777 /usr/share/jenkins/agent.jar RUN chmod 777 /usr/local/bin/jenkins-slave
2.2 JenkinsSlave腳本
#!/bin/bash #env | grep "JENKINS" >>env.txt #env | grep "JENKINS" echo"[DEBUG] ----nohup java -jar /usr/share/jenkins/agent.jar -jnlpUrl ${JENKINS_URL}/computer/${JENKINS_AGENT_NAME}/slave-agent.jnlp -secret ${JENKINS_SECRET} -workDir /home/jenkins/agent >slave.log & -----" java -jar /usr/share/jenkins/agent.jar -jnlpUrl ${JENKINS_URL}/computer/${JENKINS_AGENT_NAME}/slave-agent.jnlp -secret ${JENKINS_SECRET} -workDir "/home/jenkins/agent"
3.附加資料
jenkins slave pod的環境變量
SSO_PORT_8443_TCP_ADDR=172.30.49.148 JENKINS_SECRET=0d5d47fe01f40be6a8619f15658c7ceabfb572dc8d0eaff81f09e8b7b7bc21be KUBERNETES_PORT=tcp://172.30.0.1:443 GITLAB_CE_PORT_22_TCP_ADDR=172.30.101.86 GITLAB_CE_REDIS_SERVICE_PORT=6379 KUBERNETES_SERVICE_PORT=443 GITLAB_CE_REDIS_PORT=tcp://172.30.96.128:6379 JENKINS_JNLP_PORT=tcp://172.30.203.97:50000 JENKINS_JNLP_SERVICE_PORT=50000 TOMCAT_SERVICE_PORT_8080_TCP=tcp://172.30.83.232:8080 GITLAB_CE_REDIS_SERVICE_PORT_6379_REDIS=6379 GITLAB_CE_REDIS_PORT_6379_TCP_ADDR=172.30.96.128 SSO_PORT_8443_TCP_PORT=8443 HOSTNAME=jenkins-slave-3x91r-jng3h CUS_SERVICE_PORT_8080_TCP_ADDR=172.30.126.105 SSO_PORT=tcp://172.30.49.148:8443 SSO_SERVICE_PORT=8443 GITLAB_CE_PORT_22_TCP_PORT=22 SSO_PORT_8443_TCP_PROTO=tcp CUS_SERVICE_SERVICE_HOST=172.30.126.105 DEVOPS_SERVICE_PORT_35357_TCP=tcp://172.30.100.200:35357 GITLAB_CE_PORT_80_TCP_ADDR=172.30.101.86 JENKINS_JNLP_PORT_50000_TCP=tcp://172.30.203.97:50000 GITLAB_CE_PORT_22_TCP_PROTO=tcp HOME=/home/jenkins GITLAB_CE_REDIS_PORT_6379_TCP_PORT=6379 KUBERNETES_PORT_53_TCP_ADDR=172.30.0.1 GITLAB_CE_REDIS_PORT_6379_TCP_PROTO=tcp CUS_SERVICE_PORT_8080_TCP_PORT=8080 JENKINS_PORT_80_TCP=tcp://172.30.217.110:80 CUS_SERVICE_PORT_8080_TCP_PROTO=tcp GITLAB_CE_PORT_80_TCP_PORT=80 CUS_WEB_SERVICE_HOST=172.30.234.55 GITLAB_CE_PORT_80_TCP_PROTO=tcp KUBERNETES_PORT_53_UDP_ADDR=172.30.0.1 KUBERNETES_PORT_53_TCP_PORT=53 KUBERNETES_PORT_53_TCP_PROTO=tcp CUS_SERVICE_SERVICE_PORT=8080 CUS_SERVICE_PORT=tcp://172.30.126.105:8080 SSO_PORT_8443_TCP=tcp://172.30.49.148:8443 EUREKA_SERVICE_SERVICE_HOST=172.30.235.146 KUBERNETES_PORT_53_UDP_PORT=53 GATEWAY_SERVICE_SERVICE_HOST=172.30.61.82 KUBERNETES_SERVICE_PORT_DNS=53 KUBERNETES_PORT_53_UDP_PROTO=udp GITLAB_CE_PORT_22_TCP=tcp://172.30.101.86:22 JAVA_VERSION=8u181 GATEWAY_SERVICE_PORT_9090_TCP_ADDR=172.30.61.82 GITLAB_CE_POSTGRESQL_PORT_5432_TCP_ADDR=172.30.120.59 GITLAB_CE_REDIS_PORT_6379_TCP=tcp://172.30.96.128:6379 CUS_SERVICE_PORT_8080_TCP=tcp://172.30.126.105:8080 DEVOPS_WEB_PORT_9002_TCP_ADDR=172.30.51.98 CUS_WEB_PORT=tcp://172.30.234.55:8088 DEVOPS_SERVICE_SERVICE_HOST=172.30.100.200 CUS_WEB_SERVICE_PORT=8088 GATEWAY_SERVICE_PORT_9090_TCP_PORT=9090 GITLAB_CE_PORT_80_TCP=tcp://172.30.101.86:80 CUS_WEB_PORT_8088_TCP_ADDR=172.30.234.55 GITLAB_CE_POSTGRESQL_SERVICE_HOST=172.30.120.59 CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1 TERM=xterm GITLAB_CE_POSTGRESQL_PORT_5432_TCP_PORT=5432 GATEWAY_SERVICE_PORT_9090_TCP_PROTO=tcp EUREKA_SERVICE_PORT_8761_TCP_ADDR=172.30.235.146 KUBERNETES_PORT_443_TCP_ADDR=172.30.0.1 GATEWAY_SERVICE_SERVICE_PORT=9090 GATEWAY_SERVICE_PORT=tcp://172.30.61.82:9090 GITLAB_CE_POSTGRESQL_PORT_5432_TCP_PROTO=tcp EUREKA_SERVICE_SERVICE_PORT=8761 EUREKA_SERVICE_PORT=tcp://172.30.235.146:8761 KUBERNETES_PORT_53_TCP=tcp://172.30.0.1:53 DEVOPS_WEB_PORT_9002_TCP_PORT=9002 DEVOPS_WEB_PORT_9002_TCP_PROTO=tcp CUS_WEB_PORT_8088_TCP_PORT=8088 GITLAB_CE_SERVICE_PORT_22_SSH=22 JAVA_DEBIAN_VERSION=8u181-b13-2~deb9u1 AGENT_WORKDIR=/home/jenkins/agent PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin KUBERNETES_PORT_53_UDP=udp://172.30.0.1:53 DEVOPS_WEB_SERVICE_HOST=172.30.51.98 CUS_WEB_PORT_8088_TCP_PROTO=tcp EUREKA_SERVICE_PORT_8761_TCP_PORT=8761 JENKINS_SERVICE_HOST=172.30.217.110 EUREKA_SERVICE_PORT_8761_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 DEVOPS_SERVICE_SERVICE_PORT=35357 DEVOPS_SERVICE_PORT=tcp://172.30.100.200:35357 KUBERNETES_PORT_443_TCP_PROTO=tcp JENKINS_URL=http://10.130.210.151:8080/ GITLAB_CE_POSTGRESQL_PORT=tcp://172.30.120.59:5432 GITLAB_CE_POSTGRESQL_SERVICE_PORT=5432 LANG=C.UTF-8 JENKINS_AGENT_NAME=jenkins-slave-3x91r-jng3h GATEWAY_SERVICE_PORT_9090_TCP=tcp://172.30.61.82:9090 KUBERNETES_SERVICE_PORT_DNS_TCP=53 GITLAB_CE_POSTGRESQL_PORT_5432_TCP=tcp://172.30.120.59:5432 GITLAB_CE_SERVICE_PORT_80_HTTP=80 DEVOPS_WEB_PORT=tcp://172.30.51.98:9002 DEVOPS_WEB_PORT_9002_TCP=tcp://172.30.51.98:9002 DEVOPS_WEB_SERVICE_PORT=9002 JENKINS_SERVICE_PORT=80 JENKINS_PORT=tcp://172.30.217.110:80 TOMCAT_SERVICE_PORT_8080_TCP_ADDR=172.30.83.232 TOMCAT_SERVICE_SERVICE_HOST=172.30.83.232 CUS_WEB_PORT_8088_TCP=tcp://172.30.234.55:8088 EUREKA_SERVICE_PORT_8761_TCP=tcp://172.30.235.146:8761 JENKINS_NAME=jenkins-slave-3x91r-jng3h GITLAB_CE_SERVICE_HOST=172.30.101.86 KUBERNETES_PORT_443_TCP=tcp://172.30.0.1:443 KUBERNETES_SERVICE_PORT_HTTPS=443 DEVOPS_SERVICE_PORT_35357_TCP_ADDR=172.30.100.200 JENKINS_JNLP_PORT_50000_TCP_ADDR=172.30.203.97 TOMCAT_SERVICE_PORT_8080_TCP_PORT=8080 KUBERNETES_SERVICE_HOST=172.30.0.1 TOMCAT_SERVICE_PORT_8080_TCP_PROTO=tcp JENKINS_SERVICE_PORT_WEB=80 GITLAB_CE_REDIS_SERVICE_HOST=172.30.96.128 JAVA_HOME=/docker-java-home PWD=/home/jenkins JENKINS_PORT_80_TCP_ADDR=172.30.217.110 JENKINS_JNLP_SERVICE_HOST=172.30.203.97 JENKINS_JNLP_SERVICE_PORT_AGENT=50000 DEVOPS_SERVICE_PORT_35357_TCP_PORT=35357 JENKINS_JNLP_PORT_50000_TCP_PORT=50000 TOMCAT_SERVICE_SERVICE_PORT=8080 JENKINS_JNLP_PORT_50000_TCP_PROTO=tcp DEVOPS_SERVICE_PORT_35357_TCP_PROTO=tcp TOMCAT_SERVICE_PORT=tcp://172.30.83.232:8080 SSO_SERVICE_HOST=172.30.49.148 JENKINS_PORT_80_TCP_PORT=80 GITLAB_CE_POSTGRESQL_SERVICE_PORT_5432_POSTGRESQL=5432 JENKINS_PORT_80_TCP_PROTO=tcp GITLAB_CE_PORT=tcp://172.30.101.86:22 GITLAB_CE_SERVICE_PORT=22View Code
外部Jenkins調用容器中Slave配置實踐