gpt4 book ai didi

gradle - While循环监视Gradle中的任务

转载 作者:行者123 更新时间:2023-12-03 05:05:47 24 4
gpt4 key购买 nike

我想监视在重新部署任务后创建的kubernetes pod,一旦完成,我想检查liquibase日志。如果成功,我要删除作业。我怎样才能做到这一点?我不想在重新部署后立即取消部署。因此,doLast不是一个选择。以下代码无法保持打印状态ob尚未完成

task undeployAfterCompleted() {
group "kubernetes"
description "Undeploy the liquibase update job after completion"

def output = new ByteArrayOutputStream()
commandLine "bash", "-c", "kubectl get po -n pbr | grep 'liquibase' | awk '{ print \$3 }'"

while(!output.toString().equals('Completed')) {
sleep(5 * 1000)
println "Job has not completed yet."
commandLine "bash", "-c", "kubectl get po -n pbr | grep 'liquibase' | awk '{ print \$3 }'"
}

tasks.undeploy.execute()
}

最佳答案

我添加了一个doLast块来实现这一点:

doLast {
String status = getStatus()
println status.length()
while (status != "Completed") {
println "not"
sleep(5 * 1000)

if (getStatus() == "Completed") {
println "did"
break
}
}
tasks.undeploy.execute()
}

关于gradle - While循环监视Gradle中的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59184964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com