-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
158 lines (157 loc) · 5.68 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
pipeline {
environment {
DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1143345873309413447/CP2upEWbggVA4T3vShFrz280xJhAHHkti_UVG0g5FPJ0ZWwD4B57MijN_TAagLbKRh-J"
}
agent none
stages {
stage('Lint Playbook files in test env') {
agent {
docker { image 'pipelinecomponents/ansible-lint' }
}
steps {
script {
sh 'ansible-lint network-management.yml'
}
}
}
stage('Start and configure the test network environment') {
agent {
docker { image 'python:3.9.17' }
}
steps {
script {
sh '''
pip3 install requests
python3.9 topology/provisioning.py
'''
}
}
}
stage('Run playbook in test env') {
agent {
docker { image 'cytopia/ansible:latest-tools' }
}
steps {
script {
sh 'ansible-playbook network-management.yml'
}
}
}
stage('Run tests reachability in test env') {
agent {
docker { image 'cytopia/ansible:latest-tools' }
}
steps {
script {
sh 'ansible-playbook roles/ansible_network_routing/tests/test.yml'
}
}
}
stage('Destroy the network test environmnent') {
agent {
docker { image 'python:3.9.17' }
}
steps {
script {
sh '''
pip3 install requests
python3.9 topology/destroy.py
'''
}
}
}
stage('Merge to master') {
agent {
docker { image 'bitnami/git' }
}
steps {
sshagent(credentials: ['ssh-credentials']) {
script {
sh '''
git checkout main
git branch -u origin/main
git merge ${BRANCH_NAME}
git push origin main
'''
}
}
}
}
stage('Lint Playbook files for prod env') {
when {
expression { GIT_BRANCH == 'origin/main' }
}
agent {
docker { image 'pipelinecomponents/ansible-lint' }
}
steps {
script {
sh 'ansible-lint network-management.yml'
}
}
}
stage('Start the production network environment') {
environment {
EVE_NG_HOST = "http://10.154.0.19"
EVE_NG_CREDS = credentials('eve-ng-creds')
}
when {
expression { GIT_BRANCH == 'origin/main' }
}
agent {
docker { image 'python:3.9.17' }
}
steps {
script {
sh '''
curl -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"${EVE-NG_CREDS_USR}","password":"${EVE-NG_CREDS_PSW}"}' ${EVE-NG_HOST}/api/auth/login
curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' ${EVE-NG_HOST}/api/labs/Prod%20-%20Network%20Automation%20Routing.unl/nodes/1/start
curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' ${EVE-NG_HOST}/api/labs/Prod%20-%20Network%20Automation%20Routing.unl/nodes/2/start
curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' ${EVE-NG_HOST}/api/labs/Prod%20-%20Network%20Automation%20Routing.unl/nodes/3/start
curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' ${EVE-NG_HOST}/api/labs/Prod%20-%20Network%20Automation%20Routing.unl/nodes/4/start
'''
}
}
}
stage('Run playbook in prod env') {
when {
expression { GIT_BRANCH == 'origin/main' }
}
agent {
docker { image 'cytopia/ansible:latest-tools' }
}
steps {
script {
sh 'ansible-playbook network-management.yml'
}
}
}
stage('Run tests reachability in prod env') {
when {
expression { GIT_BRANCH == 'origin/main' }
}
agent {
docker { image 'cytopia/ansible:latest-tools' }
}
steps {
script {
sh 'ansible-playbook roles/ansible_network_routing/tests/test.yml'
}
}
}
}
post {
success {
discordSend (description: "NetDevOps pipeline succeed", title: "${JOB_NAME}", result: "SUCCESS", webhookURL: "${DISCORD_WEBHOOK_URL}")
slackSend (color: "#028000", message: "Pipeline succeed")
}
failure {
discordSend (description: "NetDevOps pipeline failed", title: "${JOB_NAME}", result: "FAILURE", webhookURL: "${DISCORD_WEBHOOK_URL}")
slackSend (color: "#c70039", message: "Pipeline failed")
}
aborted {
discordSend (description: "NetDevOps pipeline aborted", title: "${JOB_NAME}", result: "ABORTED", webhookURL: "${DISCORD_WEBHOOK_URL}")
slackSend (color: "#8c8e92", message: "Pipeline aborted")
}
}
}