forked from CeeyIT-Solutions/JavaCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
107 lines (107 loc) · 3.46 KB
/
Copy pathJenkinsfile
File metadata and controls
107 lines (107 loc) · 3.46 KB
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
pipeline {
agent {
label 'ansible'
}
environment {
ANSIBLE_INVENTORY = '/home/ec2-user/JavaCalculator/hosts.ini'
ANSIBLE_PLAYBOOK_PATH = '/home/ec2-user/JavaCalculator'
}
stages {
stage('Checkout Code for Build') {
steps {
script {
checkout scm: [
$class: 'GitSCM',
branches: [[name: 'master']],
userRemoteConfigs: [[url: 'https://github.com/Etimdevops/JavaCalculator.git']]
]
}
}
}
stage('Build') {
steps {
script {
ansiblePlaybook(
playbook: "${ANSIBLE_PLAYBOOK_PATH}/01-Build.yml",
inventory: "${ANSIBLE_INVENTORY}",
credentialsId: 'JenkinsAns'
)
}
}
}
stage('Checkout Code for Test') {
steps {
script {
checkout scm: [
$class: 'GitSCM',
branches: [[name: 'qa']],
userRemoteConfigs: [[url: 'https://github.com/Etimdevops/JavaCalculator.git']]
]
}
}
}
stage('Test') {
steps {
script {
ansiblePlaybook(
playbook: "${ANSIBLE_PLAYBOOK_PATH}/02-Test.yml",
inventory: "${ANSIBLE_INVENTORY}",
credentialsId: 'JenkinsAns'
)
}
}
}
stage('Verify Workspace') {
steps {
script {
sh 'echo "Current workspace directory:"'
sh 'pwd'
sh 'echo "List of files in the workspace:"'
sh 'ls -la /home/ec2-user/JavaCalculator/'
}
}
}
stage('Transfer JAR') {
steps {
script {
ansiblePlaybook(
playbook: "${ANSIBLE_PLAYBOOK_PATH}/03-filetransfer.yml",
inventory: "${ANSIBLE_INVENTORY}",
credentialsId: 'JenkinsAns'
)
}
}
}
stage('Deploy') {
steps {
script {
ansiblePlaybook(
playbook: "${ANSIBLE_PLAYBOOK_PATH}/04-Deploy.yml",
inventory: "${ANSIBLE_INVENTORY}",
credentialsId: 'JenkinsAns'
)
}
}
}
}
post {
always {
script {
// Print the current working directory
sh 'pwd'
// List contents of the test-reports directory for debugging
sh 'ls -la /home/ec2-user/workspace/JenkinsAnsible/test-reports/'
// List the Jenkins workspace directory for verification
sh 'ls -la /home/ec2-user/workspace/JenkinsAnsible/'
}
// Archive test reports
archiveArtifacts artifacts: '/home/ec2-user/workspace/JenkinsAnsible/test-reports/**', allowEmptyArchive: true
}
success {
echo 'Pipeline completed successfully.'
}
failure {
echo 'Pipeline failed.'
}
}
}