Skip to content
Snippets Groups Projects
Commit a81fe585 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-1784 jenkinsfile

parent 11c8cd3d
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,7 @@ pipeline {
parallel(
startGoofy: {
startGoofy(namespace, stageName, 'ea-values.yaml')
startGoofy(namespace, 'ea-values.yaml', IMAGE_TAG)
},
startPluto: {
startPluto(namespace, 'ea-values.yaml')
......@@ -103,7 +103,7 @@ pipeline {
parallel(
startGoofy: {
startGoofy(namespace, stageName, 'values.yaml')
startGoofy(namespace, 'values.yaml', IMAGE_TAG)
},
startPluto: {
startPluto(namespace, 'values.yaml')
......@@ -166,17 +166,17 @@ Void startPluto(String namespace, String values) {
}
}
Void startGoofy(String stageName, String namespace, String values) {
Void startGoofy(String namespace, String values, String imageTag) {
container("k8s") {
dir('goofy-client/apps/goofy-e2e/deployment-values/goofy') {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
sh "helm upgrade --install --create-namespace goofy goofy -f ${values} --set image.tag=${IMAGE_TAG} --namespace ${namespace}" + ' --repo https://nexus.ozg-sh.de/repository/ozg-base-apps --username ${USER} --password ${PASSWORD} --wait --wait-for-jobs'
sh "helm upgrade --install --create-namespace goofy goofy -f ${values} --set image.tag=${imageTag} --namespace ${namespace}" + ' --repo https://nexus.ozg-sh.de/repository/ozg-base-apps --username ${USER} --password ${PASSWORD} --wait --wait-for-jobs'
}
}
createKeycloakGroups(stageName)
generateKeycloakUserYaml(stageName)
applyKeycloakUser(stageName)
createKeycloakGroups(namespace)
generateKeycloakUserYaml(namespace)
applyKeycloakUser(namespace)
}
}
......@@ -195,7 +195,7 @@ Void shutdownEnvironment(String namespace) {
sh "helm uninstall goofy --namespace ${namespace} --wait"
sh "helm uninstall pluto --namespace ${namespace} --wait"
removeKeycloakUser(stageName)
removeKeycloakUser(namespace)
sh "kubectl delete namespace ${namespace}"
}
......@@ -212,8 +212,7 @@ String generateNamespaceName(String stage) {
return "e2e-${branchName}${stageName}-dev"
}
Void generateKeycloakUserYaml(String stage) {
def namespace = generateNamespaceName(stage)
Void generateKeycloakUserYaml(String namespace) {
def e2eUserFiles = sh (script: 'ls goofy-client/apps/goofy-e2e/src/fixtures/user', returnStdout: true)
e2eUserFiles.split("\\n").each { user ->
......@@ -252,7 +251,7 @@ Void createKeycloakGroups(String realm) {
def groupFiles = sh (script: 'ls goofy-client/apps/goofy-e2e/src/fixtures/group', returnStdout: true)
groupFiles.split("\\n").each { group ->
def groupJson = readJSON file: 'goofy-client/apps/goofy-e2e/src/fixtures/group/'+group
def groupJson = sh (script: "cat goofy-client/apps/goofy-e2e/src/fixtures/group/${group}", returnStdout: true)
sh """curl -X POST 'https://sso.dev.ozg-sh.de/auth/admin/realms/${realm}/groups' \
-H 'Content-Type: application/json' \
......@@ -262,8 +261,8 @@ Void createKeycloakGroups(String realm) {
}
}
Void applyKeycloakUser(String stage) {
dir(generateNamespaceName(stage)){
Void applyKeycloakUser(String namespace) {
dir(namespace){
def kcUserFiles = sh (script: "ls", returnStdout: true)
kcUserFiles.split("\\n").each { user ->
......@@ -272,8 +271,8 @@ Void applyKeycloakUser(String stage) {
}
}
Void removeKeycloakUser(String stage) {
dir(generateNamespaceName(stage)){
Void removeKeycloakUser(String namespace) {
dir(namespace){
def kcUserFiles = sh (script: "ls", returnStdout: true)
kcUserFiles.split("\\n").each { user ->
......@@ -293,7 +292,7 @@ String generateCypressConfig(String stage, String testFolder) {
config.env.dbUrl = "mongodb+srv://pluto-database-user:XnHhfznNWg65NNd@pluto-database-svc.${namespace}.svc.cluster.local/admin?ssl=false" as String
config.env.keycloakRealm = namespace as String
config.env.keycloakClient = namespace + "-goofy" as String
config.env.sabineUuid = getKeycloakUuid(namespace, 'sabine') as String
config.env.sabineUuid = getKeycloakUuid(namespace, "sabine") as String
config.integrationFolder = "./src/integration/${testFolder}" as String
config.videosFolder = "./reports/${testFolder}/videos" as String
config.screenshotsFolder = "./reports/${testFolder}/screenshots" as String
......@@ -306,22 +305,24 @@ String generateCypressConfig(String stage, String testFolder) {
}
String getKeycloakUuid(realm, userName) {
def users = sh (script: """curl -X POST 'https://sso.dev.ozg-sh.de/auth/admin/realms/${realm}/users' \
-H 'Content-Type: application/json' \
-H 'Authorization: bearer ${getKeycloakAccessToken()}'
""", returnStdout: true)
users.each { user ->
def shScript = """curl -H 'Content-Type: application/json' \
-H 'Authorization: bearer ${getKeycloakAccessToken()}' \
'https://sso.dev.ozg-sh.de/auth/admin/realms/${realm}/users'
"""
def users = readJSON text: sh(script: shScript, returnStdout: true)
for(user in users) {
if (user.username == userName) {
return user.id
return user.id
}
}
}
String getKeycloakAccessToken() {
withCredentials([usernamePassword(credentialsId: 'keycloak-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
def token = sh (script: 'curl -d "client_id=admin-cli" -d "username=$USER" -d "password=$PASSWORD" -d "grant_type=password" "https://sso.dev.ozg-sh.de/auth/realms/master/protocol/openid-connect/token"', returnStdout: true)
return access_token = token.split('"')[3]
def token = readJSON text: sh (script: 'curl -d "client_id=admin-cli" -d "username=$USER" -d "password=$PASSWORD" -d "grant_type=password" "https://sso.dev.ozg-sh.de/auth/realms/master/protocol/openid-connect/token"', returnStdout: true)
return token.access_token
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment