让 Jenkins 管道等到服务器启动 [英] Make Jenkins pipeline wait until server is up

查看:19
本文介绍了让 Jenkins 管道等到服务器启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前开始将我们的构建转换为 Jenkins 构建管道.在某个时刻,我们有必要在 docker 容器中等待 Web 应用程序的启动.

I am currently starting to convert our builds into a Jenkins build pipeline. At a certain point it is necessary for us to wait for the startup of a web application within a docker container.

我的想法是使用这样的东西:

My idea was to use something like this:

timeout(120) {
    waitUntil {
        sh 'wget -q http://server:8080/app/welcome.jsf -O /dev/null'
    }
}

不幸的是,这使得管道构建失败:

Unfortunately this makes the pipeline build fail:

错误:脚本返回退出代码 4

ERROR: script returned exit code 4

有什么简单的方法可以实现这个功能吗?

Is there any simple way to make this work?

我设法使用以下代码使其工作,但该阶段仍标记为失败(尽管构建继续并最终标记为绿色).

I managed to make it work using the following code, but the stage is still marked as failed (although the build continues and is marked green in the end).

timeout(120) {
    waitUntil {
        try {
            sh 'wget -q http://server:8080/app/welcome.jsf -O /dev/null'
            return true
        } catch (exception) {
            return false
        }
    }
}

推荐答案

他们刚刚发布了一个新版本的 管道节点和进程插件,增加了对 返回退出状态.这似乎现在可以完成工作:

They just released a new version of the Pipeline Nodes and Processes Plugin which adds support for returning the exit status. This seems to do the job now:

timeout(5) {
    waitUntil {
       script {
         def r = sh script: 'wget -q http://remoterhoste/welcome.jsf -O /dev/null', returnStdout: true
         return (r == 0);
       }
    }
}

这篇关于让 Jenkins 管道等到服务器启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆