简体   繁体   English

有没有办法判断Jenkins服务器是否已完成关闭?

[英]Is there a way to tell if a Jenkins server has finished shutting down?

I am running Jenkins on a virtual machine and calling the cli from a batch file to do a safe shutdown like so: 我在虚拟机上运行Jenkins,并从批处理文件中调用cli进行安全关机,如下所示:

java -jar $JenkinsCLILocation -s http://$JenkinsURL safe-shutdown

Once it's finished shutting down, I'm turning off the virtual machine and cloning it. 关闭完成后,我将关闭虚拟机并进行克隆。 However, I don't want to turn off the virtual machine before the safe shutdown of Jenkins is complete. 但是,我不想在安全关闭Jenkins之前关闭虚拟机。 Is there any way I can monitor the Jenkins using either the cli or a batch command to see if it's properly shut down? 有什么方法可以使用cli或批处理命令监视​​Jenkins,以查看是否已正确关闭?

This is the most ghetto hack. 这是最贫民窟的黑客。 What I'm basically doing is looking at the error output from the java command that executes the Jenkins CLI jar file, and if the error output contains "Failed to connect", I assume that the Jenkins has been shut off. 我基本上正在做的是查看执行Jenkins CLI jar文件的java命令的错误输出,如果错误输出包含“无法连接”,则我认为Jenkins已关闭。

I would love to see if anyone has a more graceful solution, cause man, this is just gross. 我很想看看是否有人有一个更优雅的解决方案,因为伙计,这简直太过分了。

while(!$JenkinsIsDown)
{
    Write-Host "Getting the session ID from Jenkins to check if it's down..."

    #This is a terrible hack so we can process the output of the command
    $JenkinsProcess = New-Object System.Diagnostics.ProcessStartInfo
    $JenkinsProcess.FileName = "java"
    $JenkinsProcess.RedirectStandardError = $true
    $JenkinsProcess.RedirectStandardOutput = $true
    $JenkinsProcess.UseShellExecute = $false
    $JenkinsProcess.Arguments = "-jar " + $JenkinsCLILocation + " -s http://" + $JenkinsURL + " session-id" 
    $JenkinsProcess.WaitForExit()
    $p = New-Object System.Diagnostics.Process
    $p.StartInfo = $JenkinsProcess
    $p.Start() | Out-Null
    $p.WaitForExit()
    $stdout = $p.StandardOutput.ReadToEnd()
    $stderr = $p.StandardError.ReadToEnd()        

    if($stderr.Contains("Failed to connect"))
    {
        Write-Host "The Jenkins is down."
        $JenkinsIsDown = $true
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理计数器程序关闭 - Batch counter program shutting down 关闭计算机套件并选择停止(.bat文件加载到服务器上) - shutting down computer suite with option to stop (.bat file loaded onto server) CMD提示:使用参数启动2个程序时程序关闭 - CMD Prompt: Program shutting down when starting 2 programs with arguments 用于判断网站是启动还是关闭的批处理脚本 - Batch script to tell if a website is up or down 告诉批处理“查找”字符串必须以换行符结尾 - Tell Batch 'find' string has to end with newline 批处理脚本-另一批处理完成后打破循环 - Batch Script - Break out of loop when another batch has finished 前一个命令执行完毕后,批处理文件运行命令 - Batch file run command after previous command has finished executing 在另一个命令批量完成后,如何“终止” Get-Content-等待? - How to “terminate” Get-Content -Wait after another command has finished in batch? 如何等待VirtualBox完成加载以在Windows批处理中执行下一个命令? - How to wait until VirtualBox has finished loading to execute next command in Windows Batch? Jenkins使用的登录凭据与登录用户的凭据不同 - Jenkins doesn't use the same credentials that the logged in user has
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM