jenkins執行腳本不退出
錯誤信息:
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /shfb_30/.jenkins/workspace/apollo_test/pom.xml to com.shfb.mobile/mobile/1.0-SNAPSHOT/mobile-1.0-SNAPSHOT.pom
[JENKINS] Archiving /shfb_30/.jenkins/workspace/apollo_test/target/mobile-1.0-SNAPSHOT.jar to com.shfb.mobile/mobile/1.0-SNAPSHOT/mobile-1.0-SNAPSHOT.jar
SSH: Connecting from host [iZ25txgf5wsZ]
SSH: Connecting with configuration [45.26_jenkins_docker] ...
SSH: EXEC: STDOUT/STDERR from command [/shfb_50G/apollo/apollo.sh] ...
開始運運行腳本
SSH: Disconnecting configuration [45.26_jenkins_docker] ...
ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 68,342 ms]
Finished: UNSTABLE
我在使用Jenkins進行遠程部署時,構建後執行的腳本沒有正常退出導致。
我的腳本沒有寫錯,幹的事情就是啟動項目。
而導致它沒有正常退出的原因是:
Since you are executing a script from a non-TTY environment; The Jenkins is not able to get the exit properly, out of your script.
意思是:因為你是從一個非tty環境執行腳本;Jenkins不能正常從你的腳本中退出。
外國網友解釋:
Since you are executing a script from a non-TTY environment; The Jenkins is not able to get the exit properly, out of your script.
因為您正在執行一個非tty環境的腳本;jenkins不能正確地離開你的腳本。
What you want is to exit immediately, after script execution! Don‘t want to wait for the entire timeout to happen and then disconnect improperly!
您想要的是在腳本執行後立即退出!不要等待整個超時發生,然後錯誤地斷開連接!
Solution: Make it Exec in PTY. (Please tick the check-box as shown in attached screenshot)
解決方案:在PTY中使用Exec
參考地址:http://stackoverflow.com/questions/11290540/jenkins-text-finder-unable-to-success-my-build/22011893#22011893
我最近(2016-10-25)在配置新項目時,發現,即使是勾選了Exec in pty,出現了項目不能啟動的問題。
?1
?2
?
執行的結果是項目沒有啟動:
之後我又去查資料,依然是在那個外國網站的下面一個人回答中,找到了解決的方法!
可能的原因是因為,在執行openapi start 命令時,剛啟動,pty(偽終端)就斷開連接,
解決的辦法就是,讓腳步在後臺運行,也就即使偽終端斷開了,項目依然可以啟動完成。
之後我執行的腳本改為
nohup sh ggf10service.sh
?1
其實就是在前面加上nohup;
外國網友後面還加了sleep 1:nohup sh ggf10service.sh & sleep 1
,
我沒有加也可以!
這裏還需要註意的地方是,啟動成功後,Jenkins控制臺會打印這麽一句話
nohup: ignoring input and appending output to `nohup.out‘
?1
也就是說,當我們使用nohup命令的的時候,日誌會被打印到nohup.out文件中去。
如果我們不做任何處理,會隨著每次的重新啟動,nohup.out會越來越大。
所以我在我執行的腳本中添加了
Cat /dev/null > nohup.out
這樣每次啟動時,都會先清空掉這個文件。
公網構建mobile 和uservice 說明:
地址:101.201.31.68/jenkins
Mobile 項目名稱:mobile-api
Uservice 項目名稱:uservice
提交代碼後,無需調整其他參數,直接構建即可。
jenkins執行腳本不退出