init after rewrite

This commit is contained in:
Clemens Lauermann 2020-04-19 10:32:47 +02:00
parent 5cad96bb5b
commit 77e4d695ea

122
Jenkinsfile vendored
View File

@ -5,67 +5,113 @@ pipeline {
buildDiscarder(logRotator(artifactNumToKeepStr: '0')) buildDiscarder(logRotator(artifactNumToKeepStr: '0'))
skipDefaultCheckout(true) skipDefaultCheckout(true)
} }
parameters { parameters {
string(name: 'USERNAME', defaultValue: 'Username', description: 'Benutzername') string(
password(name: 'PASSWORD', defaultValue: '', description: 'Passwort') name: 'REPOSITORY',
string(name: 'REPOSITORY', defaultValue: '.git', description: 'URL Git-Repository DA \n default Wert: Baue Vorlage \n Ohne https://') defaultValue: 'itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git',
string(name: 'PATH', defaultValue: '', description: "Pfad zur DA in git (z.B.: dipl/)") description: 'URL git-Repository DA//'
)
string(
name: 'GIT_PATH',
defaultValue: './',
description: "Pfad zur DA in git (z.B.: dipl/)"
)
} }
stages { stages {
stage('Clean checkout of the template') { stage('Checkout DA') {
when { steps {
expression { '.git' == params.REPOSITORY }
}
steps{
cleanWs() cleanWs()
dir('HTLLE-DA-Vorlage') { script {
checkout scm // 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))
}
}
// 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}"
]]
])
}
}
stage('Build DA') {
when {
expression { 'https://itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git' != env.REPOSITORY }
}
steps {
dir(env.GIT_PATH) {
sh 'make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd)'
} }
} }
} }
stage('Build only template') { stage('Build only template') {
when { when {
expression { '.git' == params.REPOSITORY } expression { 'https://itsp.htl-leoben.at/git/Hg/HTLLE-DA-Vorlage.git' == env.REPOSITORY }
} }
steps { steps {
sh ''' // 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/. . cp -rv HTLLE-DA-Vorlage/example/. .
make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd) PATH=$PATH
'''
}
}
stage('Checkout DA') {
when {
expression { '.git' != params.REPOSITORY }
}
steps {
cleanWs()
sh "git clone --recurse-submodules --remote-submodules https://${params.USERNAME}:${params.PASSWORD}@${params.REPOSITORY} ."
}
}
stage('Build DA') {
when {
expression { '.git' != params.REPOSITORY }
}
steps {
sh '''
cd ${params.PATH}
make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd) make pdf -C HTLLE-DA-Vorlage SOURCEDIR=$(pwd)
''' '''
} }
} }
stage('Test if diplomarbeit.pdf was build') { stage('Test if diplomarbeit.pdf exists') {
steps { steps {
dir(env.GIT_PATH) {
sh "test -f diplomarbeit.pdf" sh "test -f diplomarbeit.pdf"
}
} }
} }
} }
post { post {
always { always {
emailext attachLog: true, attachmentsPattern: 'diplomarbeit.pdf*', script {
body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}", env.RECIPIENTS = ""
recipientProviders: [requestor()], // get mail addresses
subject: "Jenkins Diplomarbeit Build ${currentBuild.currentResult}" metadata = readFile(file: "${env.GIT_PATH}metadata.yaml").split('\n').each { line ->
if(line.contains("- build-notification:")) {
def mailMatch = line =~ /[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})/
env.RECIPIENTS += (mailMatch[0][0] + ";")
}
}
}
emailext attachmentsPattern: "${env.GIT_PATH}diplomarbeit.pdf*",
to: "${env.RECIPIENTS}",
subject: "[${currentBuild.currentResult}] Diplomarbeit Build #${env.BUILD_NUMBER}",
body: "Job ${env.JOB_NAME}: ${env.JOB_URL}"
} }
} }
} }