-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.yml
67 lines (67 loc) · 2.31 KB
/
Jenkinsfile.yml
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
pipeline {
agent any
tools {
nodejs "NodeJS"
}
triggers {
githubPush()
}
stages {
stage('Build') {
steps {
sh 'npm install && npm run build'
}
}
stage('Compress/Zip') {
steps {
script {
zip dir: 'build', exclude: '', glob: '', zipFile: 'build.zip', overwrite: true
}
}
}
stage('Upload ZIP to Nexus') {
steps {
script {
def props = readProperties file: 'env'
env.VERSION = props.VERSION
echo "Version is ${VERSION}"
nexusArtifactUploader artifacts: [
[
artifactId: 'sample-react-project',
classifier: '',
file: 'build.zip',
type: 'zip'
]],
credentialsId: '33b4f031-8bab-4f9f-976d-cf771b6035cb',
groupId: 'web-app.react-app',
nexusUrl: 'localhost:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: 'react-repo',
version: "${VERSION}"
}
}
}
}
post('Generate report') {
always {
script {
// Sends HTTP POST request in JSON format
def props = readProperties file: 'env'
env.VERSION = props.VERSION
env.IP_ADDRESS = props.DESTINATION_SERVER
def jobdetails = "${JOB_NAME}-${env.BUILD_NUMBER}"
def jobstatus = "${currentBuild.result}"
def myJson = "{\"Job details\": \"${jobdetails}\", \"Build status\": \"${jobstatus}\", \"Version\": \"${VERSION}\"}";
echo "${myJson}"
if("${currentBuild.result}" == "SUCCESS") {
def destination_ip = "${IP_ADDRESS}" // destination_ip of the server which listens the requests
sh "curl -v -H 'Content-Type: application/json' -X POST -d '${myJson}' ${destination_ip}"
}
else {
echo 'Build failed/aborted'
}
}
}
}
}