-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
126 lines (125 loc) · 3.98 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
114
115
116
117
118
119
120
121
122
123
124
125
126
def scmVars
pipeline {
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '5', artifactNumToKeepStr: '5', daysToKeepStr: '5', numToKeepStr: '5')
durabilityHint 'PERFORMANCE_OPTIMIZED'
timeout(5)
}
libraries {
lib('jpl-core@master') // https://github.com/joostvdg/jpl-core
lib('jpl-maven@master') // https://github.com/joostvdg/jpl-maven
}
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
volumeMounts:
- name: maven-cache
mountPath: /root/.m2/repository
volumes:
- name: maven-cache
hostPath:
path: /tmp
type: Directory
"""
}
}
stages {
stage('Test versions') {
steps {
container('maven') {
sh 'uname -a'
sh 'mvn -version'
}
}
}
stage('Checkout') {
steps {
script {
// use this if used within Multibranch or Org Job
scmVars = checkout scm
// use this if used within a Pipeline Job
// scmVars = git('https://github.com/joostvdg/maven-demo-lib.git')
}
echo "scmVars=${scmVars}"
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 --show-version'
}
}
}
stage('Version & Analysis') {
parallel {
stage('Version Bump') {
// disable when {} when used in a Pipelone
when { branch 'master' }
// requires: https://plugins.jenkins.io/pipeline-utility-steps
environment {
NEW_VERSION = gitNextSemverTagMaven('pom.xml')
}
steps {
container('maven') {
sh 'mvn versions:set -DnewVersion=${NEW_VERSION}'
}
gitTag("v${NEW_VERSION}")
}
}
stage('Sonar Analysis') {
// disable when {} when used in a Pipelone
when {branch 'master'}
// environment {
// SONAR_HOST="http://messy-vulture-sonarqube.cicd:9000"
// SONAR_TOKEN=credentials('sonar')
// }
steps {
container('maven') {
// sh 'mvn sonar:sonar -Dsonar.host.url=${SONAR_HOST} -Dsonar.login=${SONAR_TOKEN}'
withSonarQubeEnv('mysonar') {
sh 'mvn -e org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar'
}
}
}
}
}
}
stage('Publish Artifact') {
// disable when {} when used in a Pipelone
when { branch 'master' }
steps {
container('maven') {
// #1 = credentialsId for artifactory
// #2 = distributionManagement.id
generateMavenSettings('nexus', 'nexus')
sh 'mvn deploy -s jenkins-settings.xml'
}
}
post {
always {
cleanMavenSettings()
}
}
}
}
}