jenkins-shared-library/vars/verifyEnv.groovy

19 lines
838 B
Groovy
Raw Permalink Normal View History

// Deploy ke baad sach me chal raha hai ya nahi - live endpoint se check.
def call(String target) {
withEnv(["TARGET=${target}"]) {
sh '''
HOSTIP=$(awk -v t="[$TARGET]" '
$0 == t {f=1; next}
/^\\[/ {f=0}
f && /ansible_host=/ {sub(/.*ansible_host=/,""); print $1; exit}
' "$INVENTORY")
[ -n "$HOSTIP" ] || { echo "$TARGET ka host inventory me nahi mila"; exit 1; }
GOT=$(curl -sf --max-time 15 "http://$HOSTIP:$APP_PORT$HEALTH_PATH" \
| python3 -c "import sys,json;print(json.load(sys.stdin)['version'])")
echo " $TARGET ($HOSTIP) expected=$IMAGE_TAG live=$GOT"
[ "$GOT" = "$IMAGE_TAG" ] || { echo " $TARGET MISMATCH"; exit 1; }
echo " $TARGET VERIFIED"
'''
}
}