-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
93 lines (68 loc) · 3.1 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
#!groovy
import java.text.*
// pod utilisé pour la compilation du projet
podTemplate(label: 'meltingpoc-referentiel-personnes-ui-pod', nodeSelector: 'medium', containers: [
// le slave jenkins
containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:alpine'),
// un conteneur node pour construire le dist
containerTemplate(name: 'node', image: 'node', command: 'cat', ttyEnabled: true),
// un conteneur pour construire les images docker
containerTemplate(name: 'docker', image: 'tmaier/docker-compose', command: 'cat', ttyEnabled: true),
// un conteneur pour l'analyse sonar-scanner
containerTemplate(name: 'sonarscanner', image: 'mercuriete/sonar-scanner', 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-referentiel-personnes-ui-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('node') {
stage('BUILD SOURCES') {
sh 'npm install'
sh 'npm run build'
}
}
container('sonarscanner') {
stage('QUALITY') {
withCredentials([string(credentialsId: 'sonarqube_token', variable: 'token')]) {
sh 'sonar-scanner -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",
wait: false,
parameters: [string(name: 'image', value: "$now"),
string(name: 'chart', value: "referentiel-personnes-ui")]
}
}
}
}