htlle-da-vorlage/Jenkinsfile

126 lines
4.6 KiB
Plaintext
Raw Normal View History

2020-04-16 14:08:44 +02:00
pipeline {
agent { label 'docker-lehrer' }
2020-04-16 22:43:53 +02:00
2020-04-16 14:08:44 +02:00
options {
buildDiscarder(logRotator(artifactNumToKeepStr: '0'))
2020-04-17 09:07:55 +02:00
skipDefaultCheckout(true)
2020-04-16 14:08:44 +02:00
}
2020-04-19 10:32:47 +02:00
2020-04-16 14:08:44 +02:00
parameters {
2020-04-19 10:32:47 +02:00
string(
name: 'REPOSITORY',
defaultValue: 'itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git',
description: 'URL git-Repository DA//'
)
string(
name: 'GIT_PATH',
defaultValue: './',
description: "Pfad zur DA in git (z.B.: dipl/)"
)
2020-04-16 14:08:44 +02:00
}
2020-04-19 10:32:47 +02:00
2020-04-16 14:08:44 +02:00
stages {
2020-04-19 10:32:47 +02:00
stage('Checkout DA') {
steps {
2020-04-16 15:54:33 +02:00
cleanWs()
2020-04-19 10:32:47 +02:00
script {
// add https to the url if not present
env.REPOSITORY = params.REPOSITORY
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("/")) {
env.GIT_PATH += "/"
}
if(env.GIT_PATH.startsWith("/")) {
env.GIT_PATH = env.GIT_PATH.substring(1)
}
if(env.GIT_PATH.startsWith("~/")) {
env.GIT_PATH = env.GIT_PATH.substring(2, (env.GIT_PATH.length() - 1))
}
2020-04-17 09:07:55 +02:00
}
2020-04-19 10:32:47 +02:00
// checkout out the repository including submodules
// builduser acc used in git
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
shallow: false,
reference: '',
trackingSubmodules: false
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'd65d903b-21ee-4055-98aa-ef82a903e287',
url: "${env.REPOSITORY}"
]]
])
2020-04-16 15:54:33 +02:00
}
}
2020-04-19 10:32:47 +02:00
stage('Build DA') {
2020-04-16 14:08:44 +02:00
when {
2020-04-19 10:32:47 +02:00
expression { 'https://itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git' != env.REPOSITORY }
2020-04-16 14:08:44 +02:00
}
steps {
2020-04-19 10:32:47 +02:00
dir(env.GIT_PATH) {
sh 'make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd)'
}
2020-04-16 14:08:44 +02:00
}
}
2020-04-19 10:32:47 +02:00
stage('Build only template') {
2020-04-16 14:08:44 +02:00
when {
2020-04-19 10:32:47 +02:00
expression { 'https://itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git' == env.REPOSITORY }
2020-04-16 14:08:44 +02:00
}
steps {
2020-04-19 10:32:47 +02:00
// build the template with the examples from DA point of view
sh '''#!/bin/bash
mkdir HTLLE-DA-Vorlage
ls | grep -v HTLLE-DA-Vorlage | xargs mv -t HTLLE-DA-Vorlage
cp -rv HTLLE-DA-Vorlage/example/. .
2020-04-16 14:08:44 +02:00
make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd)
'''
}
}
2020-04-19 10:32:47 +02:00
stage('Test if diplomarbeit.pdf exists') {
2020-04-16 14:08:44 +02:00
steps {
2020-04-19 10:32:47 +02:00
dir(env.GIT_PATH) {
2020-04-16 15:54:33 +02:00
sh "test -f diplomarbeit.pdf"
2020-04-19 10:32:47 +02:00
}
2020-04-16 14:08:44 +02:00
}
}
}
post {
2020-04-16 14:11:06 +02:00
always {
2020-04-19 10:32:47 +02:00
script {
env.RECIPIENTS = ""
// get mail addresses
metadata = readFile(file: "${env.GIT_PATH}metadata.yaml").split('\n').each { line ->
if(line.contains("- build-notification:")) {
// remove yaml comments
if(line.contains('#')) {
line = line.substring(0, line.indexOf('#'))
}
2020-04-19 10:32:47 +02:00
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) {
env.RECIPIENTS += (mailMatch[0][0] + ";")
}
2020-04-19 10:32:47 +02:00
}
}
}
2020-04-19 11:11:37 +02:00
dir(env.GIT_PATH) {
emailext attachmentsPattern: "diplomarbeit.pdf*",
to: "${env.RECIPIENTS}",
subject: "[${currentBuild.currentResult}] Diplomarbeit Build #${env.BUILD_NUMBER}",
body: "Job ${env.JOB_NAME}: ${env.JOB_URL}"
}
2020-04-16 14:08:44 +02:00
}
}
}