lundi 20 juillet 2020

Inject IF condition Jenkinsfile

Trying to create a Jenkins job to delete Kubernetes objects.

The shell script works fine doing something like

kubectl delete service \$(kubectl get service | grep ${rescName} | awk \'{print \$1}\')"

The issue I have is that running it a second time fails with the error

error: resource(s) were provided, but no name, label selector, or --all flag specified

How can an if statement be passed in so that it first checks if the service exists before running the kubectl delete service command and prints out a message if it doesn't exist instead of erroring and failing.

Aucun commentaire:

Enregistrer un commentaire