-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjenkinsfile_templates
106 lines (90 loc) · 3.49 KB
/
jenkinsfile_templates
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
pipeline {
agent
{ docker
{ image 'python:latest' }
}
environment {
JENKINS_REPO_NAME = 'dnacenter_jenkins'
TEMPLATES_REPO_NAME = 'templates_jenkins'
GITHUB_USERNAME = 'gzapodea'
GITHUB_TOKEN = credentials('GITHUB_TOKEN')
}
options {
skipStagesAfterUnstable()
timeout(time: 15, unit: 'MINUTES')
}
stages {
stage ('Build Python Environment') {
steps {
echo('\n\nBuilding the Docker container and Installing Python libraries:..........')
sh 'git clone https://' + GITHUB_USERNAME + ':' + GITHUB_TOKEN + '@github.com/zapodeanu/' + JENKINS_REPO_NAME + '.git'
withEnv(["HOME=${env.WORKSPACE}"]) {
sh 'pip install -r ' + JENKINS_REPO_NAME + '/requirements.txt --no-warn-script-location'
echo('\n\nVerify Python version and Libraries:............')
sh 'python --version'
sh 'pip3 list'
echo('\n\nVerify Application Files:..........')
sh 'ls ' + JENKINS_REPO_NAME + '/'
}
}
}
stage ('Download the Project Repo') {
steps {
echo('\n\nDownloading the CLI Templates:..........')
sh 'git clone https://' + GITHUB_USERNAME + ':' + GITHUB_TOKEN + '@github.com/zapodeanu/' + TEMPLATES_REPO_NAME + '.git'
withEnv(["HOME=${env.WORKSPACE}"]) {
echo('\n\nVerify Templates Files:............')
sh 'ls ' + TEMPLATES_REPO_NAME + '/'
}
}
}
stage ('Deploy the CLI Templates - Lab') {
steps {
echo('\n\nLab Deploying the CLI Templates:..........')
withEnv(["HOME=${env.WORKSPACE}"]) {
echo('\n\nVerify Working Path:............')
sh 'pwd'
dir('dnacenter_jenkins') {
sh 'python3 lab_deploy_templates.py'
}
}
}
}
stage ('Deploy the CLI Templates - Production') {
steps {
echo('\n\nDeploying the CLI Templates:..........')
withEnv(["HOME=${env.WORKSPACE}"]) {
echo('\n\nVerify Working Path:............')
sh 'pwd'
dir('dnacenter_jenkins') {
sh 'python3 deploy_templates.py'
}
}
}
}
stage ('Upload Deployment Report') {
steps {
echo('\n\nVerify if the deployment report file exists:..........')
withEnv(["HOME=${env.WORKSPACE}"]) {
dir('templates_jenkins') {
sh 'ls deployment_report.json'
echo('\n\nUploading to GitHub the deployment report:..........')
sh 'git config --global user.email "gzapodea@cisco.com"'
sh 'git config --global user.name "gzapodea"'
sh 'git add deployment_report.json'
sh 'git commit -m "committed by Jenkins"'
sh 'git push origin master --force'
}
}
}
}
}
post {
cleanup {
cleanWs()
}
always {
echo '\n\nJenkins CLI Templates Deployment end'
}
}
}