-
Notifications
You must be signed in to change notification settings - Fork 2
/
jenkinsfile_new_pipeline
101 lines (97 loc) · 3.94 KB
/
jenkinsfile_new_pipeline
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
pipeline {
agent
{ docker
{
reuseNode true
image 'python:latest'
args '--name DEV -v $HOME/DockerFiles:/root/DockerFiles -u root:sudo'
}
}
environment {
JENKINS_REPO_NAME = 'GitHub repo'
GITHUB_USERNAME = 'your GitHub user Id'
GITHUB_TOKEN = credentials('GITHUB_TOKEN')
PIPELINE_NAME = 'Pipeline name'
PYTHON_APP_NAME = 'python_app.py'
HOME = "${WORKSPACE}"
}
options {
skipStagesAfterUnstable()
timeout(time: 15, unit: 'MINUTES')
}
stages {
stage ('Environment variables') {
steps {
echo('\n\nPipeline name: ' + PIPELINE_NAME + ' ..............................')
echo('App name: ' + PYTHON_APP_NAME + ' ..............................')
echo('GitHub repo name: ' + JENKINS_REPO_NAME + ' ..............................')
echo('Workspace: ' + HOME + ' ..............................')
}
}
stage ('Build Python Environment') {
steps {
echo('\n\nJenkins ' + PIPELINE_NAME + ' build start..............................')
echo('\n\nBuilding the Docker container:..............................')
}
}
stage ('Pull or Clone the source code') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
script {
if (fileExists('dnacenter_jenkins_automations')) {
echo('\n\nPull code from GitHub:..............................')
dir(JENKINS_REPO_NAME) {
sh 'git pull --ff-only https://' + GITHUB_USERNAME + ':' + GITHUB_TOKEN + '@github.com/zapodeanu/' + JENKINS_REPO_NAME + '.git'
}
}
if (!fileExists('dnacenter_jenkins_automations')) {
echo('\n\nClone code from GitHub:..............................')
sh 'git clone https://' + GITHUB_USERNAME + ':' + GITHUB_TOKEN + '@github.com/zapodeanu/' + JENKINS_REPO_NAME + '.git'
}
}
}
}
}
stage ('Install Python libraries') {
steps {
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 ('Execute Python application') {
steps {
echo('\n\nApp ' + PIPELINE_NAME + ' run:..............................')
withEnv(["HOME=${env.WORKSPACE}"]) {
echo('\n\nVerify Working Path:..............................')
sh 'pwd'
dir(JENKINS_REPO_NAME) {
sh 'python3 ' + PYTHON_APP_NAME
}
}
}
}
stage ('Output folder content') {
steps {
echo('\n\nThe ' + PIPELINE_NAME + ' files that have been created:..............................')
withEnv(["HOME=${env.WORKSPACE}"]) {
echo('\n\nVerify Working Path:..............................')
sh 'pwd'
dir(JENKINS_REPO_NAME + '/inventory') {
sh 'ls -l -A'
}
}
}
}
}
post {
always {
echo '\n\nJenkins ' + PIPELINE_NAME + ' build end'
}
}
}