-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
136 lines (131 loc) · 5.48 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
127
128
129
130
131
132
133
134
135
136
pipeline {
agent {
kubernetes {
yamlFile 'jenkins-pod.yaml'
}
}
environment {
// creates DOCKERHUB_USR and DOCKERHUB_PSW env variables
DOCKERHUB = credentials('fondahub-dockerhub')
}
stages {
stage('Build') {
steps {
container('maven') {
// run a clean build without tests to see if the project compiles
sh 'mvn clean test-compile -DskipTests=true -Dmaven.javadoc.skip=true -B -V'
}
}
}
stage('Test') {
steps {
container('maven') {
// run JUnit tests
sh 'mvn test -B -V'
}
}
post {
// collect test results
always {
junit 'target/surefire-reports/TEST-*.xml'
jacoco classPattern: 'target/classes,target/test-classes', execPattern: 'target/coverage-reports/*.exec', inclusionPattern: '**/*.class', sourcePattern: 'src/main/java,src/test/java'
archiveArtifacts 'target/surefire-reports/TEST-*.xml'
archiveArtifacts 'target/*.exec'
}
}
}
stage('Package') {
steps {
container('maven') {
sh 'mvn package -DskipTests=true -Dmaven.javadoc.skip=true -B -V'
}
}
post {
success {
archiveArtifacts 'target/*.jar'
}
}
}
stage('Static Code Analysis') {
steps {
container('maven') {
withSonarQubeEnv('fonda-sonarqube') {
sh '''
mvn sonar:sonar -B -V -Dsonar.projectKey=workflow_k8s_scheduler \
-Dsonar.branch.name=$BRANCH_NAME -Dsonar.sources=src/main/java -Dsonar.tests=src/test/java \
-Dsonar.inclusions="**/*.java" -Dsonar.test.inclusions="src/test/java/**/*.java" \
-Dsonar.junit.reportPaths=target/surefire-reports
'''
}
}
}
}
stage('Build and push Docker') {
// only push images from the master branch
when {
branch "master"
}
// agents are specified per stage to enable real parallel execution
parallel {
stage('workflow-k8s-scheduler') {
agent {
kubernetes {
yamlFile 'jenkins-pod.yaml'
}
}
steps {
container('hadolint') {
sh "hadolint --format json Dockerfile | tee -a hadolint_scheduler.json"
}
// build and push image to fondahub/workflow-k8s-scheduler
container('docker') {
sh "echo $DOCKERHUB_PSW | docker login -u $DOCKERHUB_USR --password-stdin"
sh "docker build . -t fondahub/workflow-k8s-scheduler:${GIT_COMMIT[0..7]}"
sh "docker tag fondahub/workflow-k8s-scheduler:${GIT_COMMIT[0..7]} fondahub/workflow-k8s-scheduler:latest"
sh "docker push fondahub/workflow-k8s-scheduler:${GIT_COMMIT[0..7]}"
sh "docker push fondahub/workflow-k8s-scheduler:latest"
}
}
post {
always {
archiveArtifacts "hadolint_scheduler.json"
recordIssues(
aggregatingResults: true,
tools: [hadoLint(pattern: "hadolint_scheduler.json", id: "scheduler")]
)
}
}
}
stage('vsftpd') {
agent {
kubernetes {
yamlFile 'jenkins-pod.yaml'
}
}
steps {
container('hadolint') {
sh "hadolint --format json daemons/ftp/Dockerfile | tee -a hadolint_vsftpd.json"
}
// build and push image to fondahub/vsftpd
container('docker') {
sh "echo $DOCKERHUB_PSW | docker login -u $DOCKERHUB_USR --password-stdin"
sh "docker build daemons/ftp/ -t fondahub/vsftpd:${GIT_COMMIT[0..7]}"
sh "docker tag fondahub/vsftpd:${GIT_COMMIT[0..7]} fondahub/vsftpd:latest"
sh "docker push fondahub/vsftpd:${GIT_COMMIT[0..7]}"
sh "docker push fondahub/vsftpd:latest"
}
}
post {
always {
archiveArtifacts "hadolint_vsftpd.json"
recordIssues(
aggregatingResults: true,
tools: [hadoLint(pattern: "hadolint_vsftpd.json", id: "vsfptd")]
)
}
}
}
}
}
}
}