-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathJenkinsfile
More file actions
93 lines (86 loc) · 3.46 KB
/
Jenkinsfile
File metadata and controls
93 lines (86 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
pipeline {
agent any
tools {
maven "localMaven"
jdk "Java8"
}
environment {
// This can be nexus3 or nexus2
NEXUS_VERSION = "nexus3"
// This can be http or https
NEXUS_PROTOCOL = "http"
// Where your Nexus is running
NEXUS_URL = "13.60.86.216:8081"
// Repository where we will upload the artifact
NEXUS_REPOSITORY = "loginwebapp"
// Jenkins credential id to authenticate to Nexus OSS
NEXUS_CREDENTIAL_ID = "nexusCred"
ARTIFACT_VERSION = "${BUILD_NUMBER}"
}
stages {
stage("Check out") {
steps {
script {
git branch: 'feature/nexusUpload', url: 'https://github.com/ranjit4github/LoginWebApp.git';
}
}
}
stage("mvn build") {
steps {
script {
sh "mvn clean package"
}
}
}
stage("publish to nexus") {
steps {
script {
// Read POM xml file using 'readMavenPom' step , this step 'readMavenPom' is included in: https://plugins.jenkins.io/pipeline-utility-steps
pom = readMavenPom file: "pom.xml";
// Find built artifact under target folder
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
// Print some info from the artifact found
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
// Extract the path from the File found
artifactPath = filesByGlob[0].path;
// Assign to a boolean response verifying If the artifact name exists
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: ARTIFACT_VERSION,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
// Artifact generated such as .jar, .ear and .war files.
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
}
}
stage ('Execute Ansible Play - CD'){
agent {
label 'ansible'
}
steps{
script {
git branch: 'feature/ansibleNexus', url: 'https://github.com/ranjit4github/Ansible_Demo_Project.git';
}
sh '''
ansible-playbook -e vers=${BUILD_NUMBER} roles/site.yml
'''
}
}
}
}