jenkins节点的jdk版本过低时如何曲线救国
问题:Slave节点的jdk版本过低导致jenkins服务器无法与之建立正常通信,无法传递gerrit相关参数,直接升级jdk对版本机的潜在影响较大,虽放弃。
解决办法:<jdk版本低的节点 + jdk版本正常节点 + jenkins服务器> 然后通过执行中间节点上的脚本实现间接控制构建目的;
1 pipeline代码
import groovy.transform.Field; timeout(time: 180, unit: 'MINUTES') { echo "The timeout limit is 180 minutes." } getcodenodename = "${getcodenodename}" node(getcodenodename) { def changeBranch = "change-${GERRIT_CHANGE_NUMBER}-${GERRIT_PATCHSET_NUMBER}" stage "build cgs_v3 64 and 32 rpm" echo "build cgs_v3 64 and 32 rpm" dir ("/home/svp/") { sh """ if [ ! -d "xxxxx_V3" ]; then echo "clone code" git clone ssh://admin@10.xxx.xxx.xxx:29418/${GERRIT_PROJECT} fi cd ZXEmbsys-KLinux_CGS_V3 git fetch origin ${GERRIT_REFSPEC}:${changeBranch} git checkout ${changeBranch} git log -n2 --format=short sh /home/cxy/cgs_v3_build.sh """ } }
2 拷贝可用Node的公钥到实际编译机器的 ~/.ssh/authorized_keys,实现免密登录
3 编写可用节点的执行脚本
#!/bin/bash #author:cxy #date: 2019/05/15 # fetch git project update echo "<<<<< start scp git update to cgs_v3_build_64 >>>>>>" scp -r /home/svp/xxx_V3/* root@10.xxx.xxx.xxx:/git/XXXX_V3/ if [ $? -ne 0 ];then echo "###### scp to v3_64 failed ######" exit -1 fi echo "<<<<< start scp git update to cgs_v3_build_32 >>>>>>" scp -r /home/svp/XXX_V3/* root@10.xxx.xxx.xxx:/git/XXX_V3/ if [ $? -ne 0 ];then echo "###### scp to v3_32 failed ######" exit -1 fi # login in 74 and build v3_64 ssh 10.xxx.xxx.xxx '/xxx/rpm_build' if [ $? -eq 0 ];then echo "<<<<<< build v3_64 success >>>>>>" else echo "###### fail to build v3_64 ######" exit -1 fi # login in 73 and build v3_32 ssh 10.xxx.xxx.xxx '/xxx/rpm_build' if [ $? -eq 0 ];then echo "<<<<<< build v3_32 success >>>>>>" else echo "###### fail to build v3_32 ######" exit -1 fi
说明:黑色加粗部分表示登录目标IP并再目标机上执行单引号''内的脚本;另外一种办法是使用expect脚本,执行办法 expect scp_xxx.exp 如果文件有可执行权限,./scp_xxx.exp
#!/usr/bin/expect set usernmae "root" set password "xxxx" set A_SERVERIP [lindex $argv 0] set TEST_FILE [lindex $argv 1] set timeout 20 spawn ssh ip_address expect { "(yes/no)" { send "yes\r"; exp_continue } "password:" { send "$password\r" } } expect -re "\](\$|#) " send "touch /tmp/aaa\r" expect -re "\](\$|#) " send "exit\r"
勤苦修行得自在,道力有边边亦无边!