-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile_declarative
76 lines (75 loc) · 2.77 KB
/
Jenkinsfile_declarative
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
// This pipeline deploys the flask on a third app server as an 'jenkins' account.
// So, you should set up password-less ssh for 'jenkins' account of Jenkins server to 'ubuntu' account on the app server.
// TO help jenkins get the path right -> add PATH="$HOME/.local/bin:$PATH" at end of the file /etc/profile and restart the jenkins.
pipeline {
agent {
label 'local'
}
environment {
dev_app_server = "192.168.0.112"
dev_app_user = "ubuntu"
}
options {
timestamps()
ansiColor('xterm')
timeout(time: 5, unit: 'MINUTES')
}
stages {
stage('Building') {
options {
timeout(time: 1, unit: "MINUTES")
}
steps {
echo 'Starting build'
sh '''
sudo apt -y install python3.9
sudo apt -y install python3-pip
pip3 install --upgrade pip
pip3 install virtualenv
virtualenv -p /usr/bin/python3.9 venv
. venv/bin/activate
pip3 install -r requirements.txt
'''
echo 'Building Success'
}
}
stage('Linting and Testing') {
steps {
parallel(
a: {
echo 'Starting lint'
sh '''
. venv/bin/activate
pylint --output-format=parseable --fail-under=95 app/app.py --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" | tee pylint.log || echo "pylint exited with $?"
'''
echo "Linting Success"
},
b: {
echo 'Starting test'
sh '''
. venv/bin/activate
pytest --cov=tests --cov-report term -vs
'''
echo "Testing Success"
}
)
}
}
stage('Deploy') {
steps {
echo 'Starting deploy to the app server'
sh '''
. venv/bin/activate
ssh ${dev_app_user}@${dev_app_server} "mkdir -p /home/${dev_app_user}/webapp"
rm -rf venv
echo "Env is"
echo "${WORKSPACE}"
echo "Env done"
scp -pr "${WORKSPACE}"/* ${dev_app_user}@${dev_app_server}:/home/${dev_app_user}/webapp/
ssh ${dev_app_user}@${dev_app_server} "cd /home/${dev_app_user}/webapp/; . /home/${dev_app_user}/.bashrc; . ./deploy.sh"
'''
echo "Deployment Success"
}
}
}
}