diff --git a/Jenkinsfile b/Jenkinsfile index c1c240d05ef207061c0d3c6de725f2a7609ac9e8..1b3c0a4ea09bd67f178de8e1efcfc97d57854f59 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -547,6 +547,7 @@ String generateCypressConfig(String stage, String bezeichner, String testFolder) dir('goofy-client/apps/goofy-e2e/'){ def config = readJSON file: 'cypress-ci.json' + def elasticsearchEnv = getElasticsearchEnv(namespace) config.baseUrl = "https://${bezeichner}.dev.ozg-sh.de" as String config.env.dbUrl = "mongodb+srv://pluto-database-user:XnHhfznNWg65NNd@pluto-database-svc.${namespace}.svc.cluster.local/admin?ssl=false" as String @@ -558,7 +559,12 @@ String generateCypressConfig(String stage, String bezeichner, String testFolder) config.screenshotsFolder = "./reports/${testFolder}/screenshots" as String config.reporterOptions.reportDir = "./reports/${testFolder}/mochawesome-report" as String + environment = config.env + environment.put("elasticsearch", elasticsearchEnv) + writeJSON file: configName, json: config + + sh "cat ${configName}" } return configName @@ -615,4 +621,30 @@ Void initHelmRepo() { sh 'helm repo add ozg-base-apps-snapshot https://nexus.ozg-sh.de/repository/ozg-base-apps-snapshot --username ${USER} --password ${PASSWORD}' sh 'helm repo add ozg-base-apps https://nexus.ozg-sh.de/repository/ozg-base-apps --username ${USER} --password ${PASSWORD}' } +} + +def getElasticsearchSecret(namespace) { + container("k8s"){ + script { + def elasticsearch = readJSON ( text: sh (script: "kubectl get secret elasticsearch-credentials -n ${namespace} -o jsonpath={.data}", returnStdout: true)) + + return elasticsearch + } + } +} + +String getElasticsearchEnv(namespace) { + def elasticsearchSecret = getElasticsearchSecret(namespace) + + def env = """{ + "user":"${decodeString(elasticsearchSecret.username)}", \ + "password":"${decodeString(elasticsearchSecret.password)}", \ + "index":"${decodeString(elasticsearchSecret.index)}", \ + "url":"${decodeString(elasticsearchSecret.uris)}"}""" + + return readJSON ( text: env) +} + +String decodeString(encoded) { + return sh (script: "echo -n ${encoded} | base64 --decode", returnStdout: true) } \ No newline at end of file