From db3d4fd96238b8ac0f4897d45155599bd7d02f9e Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 28 Jun 2022 15:08:58 +0200
Subject: [PATCH] wait for keycloak client creation

---
 Jenkinsfile | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index 7b3d6c7030..b494923b65 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -365,6 +365,7 @@ Void startGoofy(String namespace, String values, String imageTag, String bezeich
             }
         }
 
+        waitForKeycloakClientCreation(namespace)
         createKeycloakGroups(namespace)
         generateKeycloakUserYaml(namespace)
         applyKeycloakUser(namespace)
@@ -542,4 +543,16 @@ String getKeycloakAccessToken() {
 
 		return token.access_token
 	}
+}
+
+Void waitForKeycloakClientCreation(realm) {
+    def shScript = """curl -H 'Content-Type: application/json' \
+                        -H 'Authorization: bearer ${getKeycloakAccessToken()}' \
+                        'https://sso.dev.ozg-sh.de/auth/admin/realms/${realm}/clients' \
+                        | grep -q ${realm}-goofy
+                    """
+
+    while(sh(script: shScript, returnStatus: true)) {
+        sh 'sleep 5'
+    }
 }
\ No newline at end of file
-- 
GitLab