diff --git a/Jenkinsfile b/Jenkinsfile index 3aaf8e5..3f3f56a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,22 +42,22 @@ pipeline { // add https to the url if not present env.REPOSITORY = params.REPOSITORY - if(!env.REPOSITORY.startsWith("https://")) { + if (!env.REPOSITORY.startsWith("https://")) { env.REPOSITORY = "https://" + env.REPOSITORY } // sanitize git dir path env.GIT_PATH = params.GIT_PATH - if(env.GIT_PATH.endsWith("/")) { + if (env.GIT_PATH.endsWith("/")) { env.GIT_PATH = env.GIT_PATH.substring( 0, (env.GIT_PATH.length() - 1)) } - if(env.GIT_PATH.startsWith("/")) { + if (env.GIT_PATH.startsWith("/")) { env.GIT_PATH = env.GIT_PATH.substring(1) } - if(env.GIT_PATH.startsWith("~/")) { + if (env.GIT_PATH.startsWith("~/")) { env.GIT_PATH = env.GIT_PATH.substring(2) } - if(env.GIT_PATH.contains("../")) { + if (env.GIT_PATH.contains("../")) { error("GIT_PATH must not contain '../'") } @@ -65,7 +65,10 @@ pipeline { env.GIT_BRANCH = params.GIT_BRANCH ?: '*/master' // output archive filename - env.ARCHIVE_FILENAME = "diplomarbeit." + params.ARCHIVE_FORMAT + env.ARCHIVE_FILENAME = 'diplomarbeit.' + params.ARCHIVE_FORMAT + + // if following files exist add them to the output archive + env.ARCHIVE_FILES = 'diplomarbeit.pdf diplomarbeit.pdf.log spellcheck-results.txt' } } } @@ -153,10 +156,17 @@ pipeline { steps { dir(env.GIT_PATH) { script { - if (params.ARCHIVE_FORMAT == 'zip') { - sh "zip -q ${env.ARCHIVE_FILENAME} diplomarbeit.pdf* spellcheck-results.txt" + env.FILES_TO_INCLUDE = '' + def include = env.ARCHIVE_FILES.split(' ').each { filename -> + if (fileExists(filename)) { + env.FILES_TO_INCLUDE += (filename + ' ') + } + } + + if (env.ARCHIVE_FORMAT == 'zip') { + sh "zip -q ${env.ARCHIVE_FILENAME} ${env.FILES_TO_INCLUDE}" } else { - sh "tar -czf ${env.ARCHIVE_FILENAME} diplomarbeit.pdf* spellcheck-results.txt" + sh "tar -czf ${env.ARCHIVE_FILENAME} ${env.FILES_TO_INCLUDE}" } } } @@ -169,14 +179,14 @@ pipeline { env.RECIPIENTS = "" // get mail addresses // needs script approval in jenkins - metadata = readFile(file: "${env.GIT_PATH}/metadata.yaml").split('\n').each { line -> - if(line.contains("- build-notification:")) { + def metadata = readFile(file: "${env.GIT_PATH}/metadata.yaml").split('\n').each { line -> + if (line.contains("- build-notification:")) { // remove yaml comments - if(line.contains('#')) { + if (line.contains('#')) { line = line.substring(0, line.indexOf('#')) } def mailMatch = line =~ /[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})/ - if(mailMatch) { + if (mailMatch) { env.RECIPIENTS += (mailMatch[0][0] + ";") } }