-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
114 lines (93 loc) · 3.55 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
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
108
109
110
111
112
113
114
def allowedBranches = ["main"]
def uploadedFiles = ""
pipeline {
agent {
kubernetes {
label 'dind-agent'
}
}
environment {
GIT_AUTHOR_NAME = "Jenkins"
GIT_COMMITTER_NAME = "Jenkins"
}
stages {
stage('Getting Commit Id of Last Push') {
steps {
script {
echo "bob started building"
env.LAST_PUSH = """${sh(
returnStdout: true,
script: '''
set +x;
cat s3LastCommitPush.txt
'''
)}"""
echo "last push commit Id ${env.LAST_PUSH}"
}
}
}
stage('Uploading Asstes') {
steps {
script {
def changedFiles = """${sh(
returnStdout: true,
script: '''
set +x;
git diff ${LAST_PUSH} ${GIT_COMMIT} --name-only --diff-filter=AMR;
'''
)}""".trim().split("\n")
for (file in changedFiles) {
def contentType = ""
if (file == 'package.json') {
continue;
} else if (file ==~ '.*\\.mp4$') {
contentType = "video/mp4"
} else if (file ==~ '.*\\.mp3$') {
contentType = "audio/mpeg"
} else if (file ==~ '.*\\.png$') {
contentType = "image/png"
} else if (file ==~ '.*\\.gif$') {
contentType = "image/gif"
} else if (file ==~ '.*\\.ttf$') {
contentType = "application/font-sfnt"
} else if (file ==~ '.*\\.json$') {
contentType = "application/json"
} else if (file ==~ '.*\\.svg$') {
contentType = "image/svg+xml"
} else if (file ==~ '.*\\.jsa$') {
contentType = "binary/octet-stream"
} else if (file ==~ '.*\\.pdf$') {
contentType = "application/pdf"
} else {
continue
}
echo "bob is pushing file ${file} to s3"
def s3Path = "s3://beckn-frontend-assets/${file}"
sh "chmod +x ./push.sh"
sh ("./push.sh ${file} --no-compress --no-resize --no-check")
uploadedFiles += "\n${file}"
}
}
}
}
stage('Updating S3 Push Record') {
steps {
script {
env.SUMMARY = "Files Uploaded: ${uploadedFiles == '' ? 'NA' : uploadedFiles}"
def branchName = 'main'
def commitMessage = "[skip ci] updating s3LastCommitPush"
sh "git config user.email '[email protected]'"
sh "git config user.name 'ny-jenkins'"
sh "git remote set-url origin [email protected]:nammayatri/asset-store.git"
sh "git checkout ${branchName}"
sh "echo ${GIT_COMMIT} > s3LastCommitPush.txt"
sh "git add s3LastCommitPush.txt"
sh "git commit -m \"${commitMessage}\""
sh "git push"
echo "${SUMMARY}"
echo "bob builded successfully 😎"
}
}
}
}
}