Jenkins: Discover FQDN from env var instead of using hard-coded one.

Makes pipeline less dependent to environment.
This commit is contained in:
Johannes Schnatterer 2017-12-12 09:22:29 +01:00
parent ef3e3defd4
commit b5b2dcf1c1

14
Jenkinsfile vendored
View file

@ -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: """