jenkins 配置為node程序不在時,自動連jenkins master伺服器:
3.1 vi connectToCI.sh 3.2 輸入agent.jar命令,注意agent jar檔案路徑要寫絕對路徑 #! /bin/sh proc_name= "slave-agent.jnlp" #程序名 proc_num() { num=`ps -ef | grep $proc_name | grep -v grep | wc -l` return $num } proc_num number=$? #獲取程序數量 if [ $number -eq 0 ] then #這裡的執行命令, 直接從node節點建立後的jenkins中複製過來的 nohup java -jar /home1/xxx/jenkins/agent.jar -jnlpUrl http://jenkins的url地址/computer/console_pr_linux_64bit_node_01/slave-agent.jnlp -secret eb669bd77cb578cfca15cedf3ec9d8ccc75aeeb096f68d9d4232e2cca82aac3f -workDir "/home1/irteam/jenkins" & fi 3.3 chmod +777 connectToCI.sh 3.4 crontab -e 3.5 輸入以下內容 [irteam@testa-jenkins1-ncl ~]$ crontab -e SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed */1 * * * * sh /home1/irteamx/connectToCI.sh #若沒有指定-u , 那預設會以當前使用者執行,每分鐘檢測,若程序不在,自動重連