forked from MithunTechnologiesDevOps/maven-web-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinswithAnsible
49 lines (35 loc) · 1007 Bytes
/
JenkinswithAnsible
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
pipeline{
agent {
label 'ansible'
}
environment {
AWS_EC2_PRIVATE_KEY=credentials('ec2-private-key')
}
tools{
maven 'maven3.8.2'
}
options{
timestamps()
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', daysToKeepStr: '', numToKeepStr: '5'))
}
stages{
stage('CheckOutCode'){
steps{
git branch: 'master', credentialsId: '957b543e-6f77-4cef-9aec-82e9b0230975', url: 'https://github.com/MithunTechnologiesDevOps/maven-web-application.git'
}
}
stage('Build'){
steps{
sh "mvn clean package"
}
}
stage('DeployApp'){
steps{
//List the dymaic inventory just for verification
sh "ansible-inventory --graph -i aws_ec2.yaml"
//Run playbook using dynamic inventory & limit exuection only fo tomcatservers.
sh "ansible-playbook -i aws_ec2.yaml appdeploy.yaml -u ec2-user --private-key=$AWS_EC2_PRIVATE_KEY --limit tomcatservers --ssh-common-args='-o StrictHostKeyChecking=no'"
}
}
}//Stages Closing
}