检查应用程序是否已部署,如果已在 Jenkins 中使用 Bash 部署,则取消部署

Check if an app is deployed and undeploy it if it is deployed using Bash in Jenkins

我正在使用 Junkins 中的一项工作来构建我的应用程序 (.ear),然后将其部署到 Glassfish 中。我想在部署我的应用程序(新版本)之前执行 asadmin undeploy myApp。问题是在第一次执行时没有部署应用程序,因此执行 asadmin undeploy myApp 会产生错误。任何处理这种情况的建议。任何提议都是最受欢迎的。谢谢。


编辑:

如果我的方法不对,请指正我,也许我做错了!这是拥有软件生产链的正确方法吗?我是否必须停止服务器并重新启动它?

我从未使用过Glassfish,但您可以检查您的应用程序是否已部署,然后再执行取消部署。

如果您知道您的应用程序应该在哪个端口执行,您可以简单地使用 netstat 或 lsof 进行检查。

编辑:

查看 this doc(示例 2–3 上市申请),似乎您可以通过以下方式看到:

list-applications --type web

对此:

Correct me if I am wrong in my method, maybe I am doing things wrong! Is this the right way to have a chain of production of a sowtware? Do I have to stop the server and restart it?

我认为正确的答案是它取决于您使用的网络服务器(例如 Glassfish 提供 autodeploy)。但总的来说,这种方法是有效的。

在 Bash 上观看了一些视频并在 Davide Patti 提供的帮助下,我想出了怎么做。

知道我使用了 Davide Patti 的答案并且我感谢他的帮助我选择写我自己的答案的原因很简单:Patti 的答案没有用。

为了测试应用程序是否已部署并在已部署时取消部署,我使用了以下对我有用的 Bash 代码:

apps=`asadmin list-applications -t --user=admin --passwordfile=password.txt`

for app in $apps
do
    if [ $app = "the_name_of_your_app" ]
    then
        asadmin --user=admin --passwordfile=password.txt undeploy the_name_of_your_app
    fi
done;

PS:password.txt的内容是一行:AS_ADMIN_PASSWORD=admin