forked from joostvdg/maven-demo-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
113 lines (112 loc) · 3.12 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def scmVars
pipeline {
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '5', artifactNumToKeepStr: '5', daysToKeepStr: '5', numToKeepStr: '5')
timeout(15)
}
libraries {
lib('core@master')
lib('maven@master')
}
agent {
kubernetes {
label 'mypod'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: some-label-value
spec:
containers:
- name: maven
image: maven:3-jdk-8
command:
- cat
tty: true
"""
}
}
stages {
stage('Test versions') {
steps {
container('maven') {
sh 'uname -a'
sh 'mvn -version'
}
}
}
stage('Checkout') {
steps {
script {
scmVars = checkout scm
}
echo "scmVars=${scmVars}"
//gitRemoteConfig('joostvdg', 'maven-demo-lib', 'githubtoken')
gitRemoteConfigByUrl(scmVars.GIT_URL, 'githubtoken')
sh '''
git config --global user.email "[email protected]"
git config --global user.name "Jenkins"
'''
//sh 'env'
}
}
stage('Build') {
steps {
container('maven') {
sh 'mvn clean verify -C -e'
}
}
}
stage('Version & Analysis') {
parallel {
stage('Version Bump') {
when { branch 'master' }
environment {
NEW_VERSION = gitNextSemverTagMaven('pom.xml')
}
steps {
container('maven') {
sh 'mvn versions:set -DnewVersion=${NEW_VERSION}'
}
gitTag("v${NEW_VERSION}")
}
}
stage('Sonar Analysis') {
when {branch 'master'}
environment {
SONAR_HOST="http://sonar-sonarqube:9000"
SONAR_TOKEN=credentials('sonar')
}
steps {
container('maven') {
sh 'mvn sonar:sonar -Dsonar.host.url=${SONAR_HOST} -Dsonar.login=${SONAR_TOKEN}'
}
}
}
}
}
stage('Publish Artifact') {
when { branch 'master' }
steps {
container('maven') {
// #1 = credentialsId for artifactory
// #2 = distributionManagement.id
generateMavenSettings('artifactory', 'releases')
sh 'mvn deploy -s jenkins-settings.xml'
}
}
post {
always {
cleanMavenSettings()
}
}
}
}
post {
always {
cleanWs()
}
}
}