1

i have a jenkins job that is executing a shell, i want it to wait , if a particular condition is not as per desired state,, but the job executes with 22 sec, where as i have asked it to wait for 30 sec, as the condition is currently not in desired state,,

#!/bin/bash
container_name=$(helm install "$USER"-0.1.0.tgz | grep -A2  "v1/Pod(related)" | awk 'NR>2' | awk '{ print $1 }')
container_status=$(kubectl get pod "$container_name" | grep "$container_name" | awk '{ print $3 }')
count=0
if  [ "$container_status" != "Running" ]
   then 
      sleep 10
      count+=1
      if  [ $count -eq 3 ]
        then
          break
      fi          
   else 
      echo "Container is Ready!!"
fi      
  • You have put a sleep of 10 seconds in. This is not 30 seconds? – Raman Sailopal Feb 5 '18 at 12:51
2

It looks like you want to make that:

#!/bin/bash

while [ "$container_status" != "Running" ] ; do
    ...
done

because currently you will only go through that code once (and thus the count will never reach three anyway).

If you want to detect when something is “ready” you could do worse than use the old trick of reading from a named pipe, and have a separate (sub)process write to the pipe when it's ready.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.