From b5b2dcf1c1455a4824fa9265f45833fff5417798 Mon Sep 17 00:00:00 2001 From: Johannes Schnatterer Date: Tue, 12 Dec 2017 09:22:29 +0100 Subject: [PATCH] Jenkins: Discover FQDN from env var instead of using hard-coded one. Makes pipeline less dependent to environment. --- Jenkinsfile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8ad049d76..c95dde4c8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ #!groovy node { - cesFqdn = "ecosystem.cloudogu.net" + cesFqdn = findHostName() cesUrl = "https://${cesFqdn}" credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME') @@ -21,7 +21,7 @@ node { parallel( test: { stage('Test') { - String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; + String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606" mvn "${jacoco}:prepare-agent test ${jacoco}:report" } }, @@ -72,6 +72,16 @@ void mvn(String args) { sh 'rm -f settings.xml' } +String findHostName() { + String regexMatchesHostName = 'https?://([^:/]*)' + + // Storing matcher in a variable might lead to java.io.NotSerializableException: java.util.regex.Matcher + if (!(env.JENKINS_URL =~ regexMatchesHostName)) { + script.error 'Unable to determine hostname from env.JENKINS_URL. Expecting http(s)://server:port/jenkins' + } + return (env.JENKINS_URL =~ regexMatchesHostName)[0][1] +} + void writeSettingsXml() { withCredentials([credentials]) { writeFile file: "settings.xml", text: """