-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
68 lines (60 loc) · 2.02 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
pipeline {
agent {
label 'test-agent'
}
environment {
IMAGE_NAME = 'ghcr.io/sdpxultimate/jenkins-assignment'
REGISTRY_CREDENTIALS = credentials('ghcr-credentials')
APP_NAME = 'web-api'
ROBOT_REPO = 'https://github.com/sdpxultimate/jenkins-robot'
ROBOT_BRANCH = 'main'
}
stages {
stage('Install & Run Unittest') {
steps {
sh "pip install -r requirements.txt"
sh "python3 unit_test.py"
}
}
stage('Create Image') {
steps {
sh "docker build -t ${IMAGE_NAME}:${BUILD_ID} ."
}
}
stage('Run Container & Run Robot Testing') {
steps {
sh "docker run -dp 5000:5000 --name ${APP_NAME} ${IMAGE_NAME}:${BUILD_ID}"
git branch: "${ROBOT_BRANCH}", url: "${ROBOT_REPO}"
sh "robot plus.robot"
}
post {
always {
sh returnStatus: true, script: "docker stop ${APP_NAME}"
sh returnStatus: true, script: "docker rm ${APP_NAME}"
}
}
}
stage('Push Image to Registry') {
steps {
sh 'echo $REGISTRY_CREDENTIALS_PSW | docker login ghcr.io -u $REGISTRY_CREDENTIALS_USR --password-stdin'
sh "docker push ${IMAGE_NAME}:${BUILD_ID}"
}
}
stage('Deploy') {
agent {
label 'pre-prod-agent'
}
steps {
sh returnStatus: true, script: "docker stop ${APP_NAME}"
sh returnStatus: true, script: "docker rm ${APP_NAME}"
sh 'echo $REGISTRY_CREDENTIALS_PSW | docker login ghcr.io -u $REGISTRY_CREDENTIALS_USR --password-stdin'
sh "docker run -dp 5001:5000 --name ${APP_NAME} ${IMAGE_NAME}:${BUILD_ID}"
}
}
}
post {
always {
sh "docker system prune -af"
}
}
}