Reputation: 727
I can't seem to get the variable glooNamespaceExists
to actually print.I see in the console the response from kubectl
is there but the variable seems to be null
- I'm looking to skip this entire build stage if the namespace already exists..
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: Console output of 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
Upvotes: 1
Views: 244
Reputation: 9184
Please add returnStdout: true
to your script command which will return exact output. Otherwise it will return status code which 0
. Please add returnStdout: true
like this so your command should be like this,
def glooNamespaceExists = sh(script: "kubectl get ns gloo-system -o jsonpath='{.status.phase}'", returnStdout: true)
Upvotes: 2