forked from phil-form/java_front
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
44 lines (40 loc) · 1.5 KB
/
Copy pathJenkinsfile
File metadata and controls
44 lines (40 loc) · 1.5 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
pipeline {
agent any
environment {
SSH_SERVER = credentials('ssh-server')
SSH_KEY_CREDENTIALS_ID = 'prod-server-key'
DEPLOY_PATH = credentials('deployment-prod')
}
stages {
stage("Build container") {
steps {
// !!!! Attention !!!! : Assurez-vous que :
// 1. Docker est installé et configuré sur votre machine Jenkins.
// 2. Votre Jenkins a les permissions nécessaires pour exécuter des commandes Docker.
sh 'docker --version'
// On supprime l'image existante pour éviter les conflits.
sh 'docker image rm -f front || true'
sh 'docker build -t front .'
// Exporter l'image
sh 'docker save front -o ./front.tar'
}
}
stage('Deploy SSH') {
steps {
sshagent([env.SSH_KEY_CREDENTIALS_ID]) {
sh '''
scp ./front.tar $SSH_SERVER:$DEPLOY_PATH/
ssh $SSH_SERVER "
cd $DEPLOY_PATH
docker compose stop deployment-front || true
docker compose rm deployment-front || true
docker image rm front || true
docker load -i front.tar
docker compose up front -d
"
'''
}
}
}
}
}