-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
61 lines (53 loc) · 2.34 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
pipeline {
agent any
stages {
stage('Checkout') {
steps {
// Clean workspace and checkout the code from the GitHub repository
cleanWs()
git branch: 'main', url: 'https://github.com/sidgolangade/Web-Application-Repository.git'
}
}
stage('Build') {
steps {
// Install Python and required dependencies
sh 'pip install -r requirements.txt'
// Any additional build steps you may have
// Collect static files (if applicable)
//sh 'python manage.py collectstatic --noinput'
}
}
stage('Test') {
steps {
// Run tests for the Django application
sh 'python manage.py test'
}
}
stage('Archive Artifacts') {
steps {
archiveArtifacts(artifacts: '**/*', excludes: '')
}
}
stage('Deploy to Ansible Server') {
steps {
// Copy the built application code to the Ansible Server
withCredentials([sshUserPrivateKey(credentialsId: '2a67236b-f587-44a4-90f2-1e8ba1e8d313', keyFileVariable: 'SSH_PRIVATE_KEY')]) {
sh '''
rsync -e "ssh -o StrictHostKeyChecking=no -i $SSH_PRIVATE_KEY" -av --exclude venv/ ./ [email protected]:/home/ec2-user/ansible-data/
'''
}
}
}
// scp -o StrictHostKeyChecking=no -i "$SSH_PRIVATE_KEY" -r ./* [email protected]:/home/ec2-user/ansible-data
stage('Deploy using Ansible') {
steps {
// Run Ansible playbook on the Ansible Server
withCredentials([sshUserPrivateKey(credentialsId: '2a67236b-f587-44a4-90f2-1e8ba1e8d313', keyFileVariable: 'SSH_PRIVATE_KEY')]) {
sh '''
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "$SSH_PRIVATE_KEY" [email protected] 'ansible-playbook -i /etc/ansible/hosts /home/ec2-user/ansible-data/ansible-playbooks/deploy-web-app.yml'
'''
}
}
}
}
}