forked from dbarentine/keycloak-wsfed
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Jenkinsfile
75 lines (74 loc) · 3.08 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pipeline {
agent any
options {
timestamps()
timeout(time: 3600, unit: 'SECONDS')
}
parameters {
string(name: 'CREATE_RELEASE', defaultValue: 'false')
string(name: 'VERSION', defaultValue: '')
string(name: 'REPO_URL', defaultValue: '')
string(name: 'BROWSER', defaultValue: 'htmlunit')
string(name: 'SKIP_TESTS', defaultValue: 'false')
}
environment{
APP="keycloak-wsfed"
}
stages {
stage('Build') {
agent {
label 'jenkins-slave-maven-ct'
}
steps {
script {
sh 'printenv'
def options = ""
if (params.BROWSER == "chrome") {
options = '-DwebdriverDownloadBinaries=false -DchromeArguments="--headless --no-sandbox --disable-dev-shm-usage --disable-gpu"'
} else if (params.BROWSER == "firefox") {
options = '-DwebdriverDownloadBinaries=false -DfirefoxArguments="-headless"'
}
withCredentials([usernamePassword(credentialsId: 'cloudtrust-cicd-sonarqube', usernameVariable: 'USER', passwordVariable: 'PASSWD')]) {
def sonar_opts = "\"-Dsonar.login=${USER}\" \"-Dsonar.password=${PASSWD}\""
sh """
mvn -B -T4 clean package \
-Dbrowser=\"${params.BROWSER}\" \
${options} \
-DskipTests=${params.SKIP_TESTS} \
spotbugs:spotbugs pmd:pmd dependency-check:check \
-Dsonar.java.spotbugs.reportPaths=target/spotbugsXml.xml \
-Dsonar.java.pmd.reportPaths=target/pmd.xml \
${sonar_opts} \
sonar:sonar
"""
}
if (params.CREATE_RELEASE == "true") {
echo "creating release ${VERSION} and uploading it to ${REPO_URL}"
// upload to repo
withCredentials([usernamePassword(credentialsId: 'cloudtrust-cicd-artifactory-opaque', usernameVariable: 'USR', passwordVariable: 'PASSWD')]){
sh """
cd "${APP}/target"
mv "${APP}"-?.?.?*.tar.gz "${APP}-${params.VERSION}.tar.gz"
curl --fail -k -u"${USR}:${PASSWD}" -T "${APP}-${params.VERSION}.tar.gz" --keepalive-time 2 "${REPO_URL}/${APP}-${params.VERSION}.tar.gz"
"""
}
if (!env.TAG_NAME && env.TAG_NAME != params.VERSION) {
withCredentials([usernamePassword(credentialsId: "cloudtrust-cicd-support-triustid-ch",
usernameVariable: 'USR',
passwordVariable: 'PASSWD')]) {
def git_url = "${env.GIT_URL}".replaceFirst("^(http[s]?://www\\.|http[s]?://|www\\.)","")
sh("git config --global user.email '[email protected]'")
sh("git config --global user.name 'ci'")
sh("git tag ${VERSION} -m 'CI'")
sh("git push https://${USR}:${PASSWD}@${git_url} --tags")
}
} else {
echo "Tag ${env.TAG_NAME} already exists. Skipping."
}
echo "release ${VERSION} available at ${REPO_URL}/${APP}-${params.VERSION}.tar.gz"
}
}
}
}
}
}