I’m trying to delete pods through Jenkins stage. But for loop not working to delete pods. Any suggestions?
stage(' second') {
withCredentials([usernamePassword(credentialsId:"xxx", passwordVariable: 'xxx', usernameVariable: 'xxx')])
{
sh '''
xxxx logging into cluster working here <===
pods= $(oc -n ns get pods | grep -i pod** | awk {'print $1'}) <=== getting list of pods working fine
for pod in "${pods}"
do
echo "$pod"
oc -n ns delete $pod;
done
'''
}
}
## Heading ##
CodePudding user response:
Probably you should remove the double quotes surrounding "${pods}"
. Something like below.
for pod in ${pods}
do
echo "$pod"
oc -n ns delete $pod;
done
Also if your default shell is not Bash
try setting the shebang
line at the top of your sh
block.
#!/bin/bash
CodePudding user response:
Remove this space: pods= $(oc
You can verify by echo "${pods}'
right after setting.