-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
84 lines (60 loc) · 2.87 KB
/
Copy pathJenkinsfile
File metadata and controls
84 lines (60 loc) · 2.87 KB
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
#!groovy
import java.text.SimpleDateFormat
// pod utilisé pour la compilation du projet
podTemplate(label: 'meltingpoc-api-gateway-pod', nodeSelector: 'medium', containers: [
// le slave jenkins
containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:alpine'),
// un conteneur pour le build maven
containerTemplate(name: 'gradle', image: 'elkouhen/gradle-docker', privileged: true, ttyEnabled: true, command: 'cat'),
// un conteneur pour construire les images docker
containerTemplate(name: 'docker', image: 'tmaier/docker-compose', command: 'cat', ttyEnabled: true),
// un conteneur pour déployer les services kubernetes
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl', command: 'cat', ttyEnabled: true)],
// montage nécessaire pour que le conteneur docker fonction (Docker In Docker)
volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')]
) {
node('meltingpoc-api-gateway-pod') {
def branch = env.JOB_NAME.replaceFirst('.+/', '');
properties([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '1',
artifactNumToKeepStr: '1',
daysToKeepStr: '3',
numToKeepStr: '3'
)
)
])
def now = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
stage('CHECKOUT') {
checkout scm
}
container('gradle') {
stage('BUILD SOURCES') {
withCredentials([string(credentialsId: 'sonarqube_token', variable: 'token')]) {
sh 'gradle clean build -Dsonar.login=${token}'
}
}
}
container('docker') {
stage('BUILD DOCKER IMAGE') {
sh 'mkdir /etc/docker'
// le registry est insecure (pas de https)
sh 'echo {"insecure-registries" : ["registry.k8.wildwidewest.xyz"]} > /etc/docker/daemon.json'
withCredentials([usernamePassword(credentialsId: 'nexus_user', usernameVariable: 'username', passwordVariable: 'password')]) {
sh "docker login -u ${username} -p ${password} registry.k8.wildwidewest.xyz"
}
sh "tag=$now docker-compose build"
sh "tag=$now docker-compose push"
}
}
container('kubectl') {
stage('RUN') {
build job: '/SOFTEAMOUEST/chart-run/master', parameters: [
string(name: 'image', value: "$now"),
string(name: 'chart', value: "api-gateway"),
string(name: 'alias', value: "meltingpoc")], wait: false
}
}
}
}