我似乎无法实际打印变量glooNamespaceExists。我在控制台中看到来自kubectl的响应,但该变量似乎是null -如果名称空间已经存在,我希望跳过整个构建阶段。
stage('Setup Gloo Ingress Controller') {
def glooNamespaceExists = sh(script: "kubectl get ns gloo-system -o jsonpath='{.status.phase}'")
if (glooNamespaceExists != 'Active') {
sh 'helm repo add gloo https://storage.googleapis.com/solo-public-helm'
sh 'helm repo update'
sh 'kubectl create namespace gloo-system'
sh 'helm install gloo gloo/gloo --namespace gloo-system'
}
}EDIT: run的控制台输出:
[Pipeline] { (Setup Gloo Ingress Controller)
[Pipeline] sh
+ kubectl get ns gloo-system -o jsonpath={.status.phase}
Active
[Pipeline] sh
+ helm repo add gloo https://storage.googleapis.com/solo-public-helm发布于 2021-06-25 17:42:46
请将returnStdout: true添加到脚本命令中,该命令将返回准确的输出。否则,它将返回0的状态代码。请像这样添加returnStdout: true,这样你的命令应该是这样的。
def glooNamespaceExists = sh(script: "kubectl get ns gloo-system -o jsonpath='{.status.phase}'", returnStdout: true)https://stackoverflow.com/questions/68128599
复制相似问题