Skip to content

Commit

Permalink
dummy push 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishsingh101 committed Mar 9, 2024
1 parent 263aea7 commit ae25a03
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 5 deletions.
95 changes: 90 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def allowedBranches = ["main"]
def allowedBranches = ["main", "jenkins"]

def uploadedFiles = ""

Expand All @@ -8,14 +8,99 @@ pipeline {
GIT_AUTHOR_NAME = "Jenkins User"
GIT_COMMITTER_NAME = "Jenkins User"
}

stages {

stage('Uploading dummy Assets') {
stage('Checkout') {
steps {
scmSkip(deleteBuild: false, skipPattern:'.*\\[skip ci\\].*')
script {
if (!(env.BRANCH_NAME in allowedBranches)) {
currentBuild.result = 'ABORTED'
error 'Build not allowed for branch ${env.BRANCH_NAME}'
} else if (sh(script: "git log -1 --pretty=%B | grep -F -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) == 0) {
currentBuild.result = 'ABORTED'
error 'Aborting because commit message contains [skip ci]'
}
}
}
}

stage('Getting Commit Id of Last Push') {
steps {
script {
echo "last push commit Id ${env.LAST_PUSH}"
env.LAST_PUSH = """${sh(
returnStdout: true,
script: '''
set +x;
cat s3LastCommitPush.txt
'''
)}"""
}
}
}

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 {
continue
}

echo "pushing file ${file}"

// def s3Path = "s3://${S3_BUCKET}/${file}"
// sh ("aws s3 cp ./${file} ${s3Path} --metadata ' {\"commit-id\":\"'${GIT_COMMIT}'\", \"last-modified-by\":\"Jenkins\"}' --content-type '${contentType}' --acl public-read")
// uploadedFiles += "\n${file}"

echo "starting s3 push .........................."
def s3Path = "s3://beckn-frontend-assets/${file}"
sh ("aws s3 cp ./${file} ${s3Path}")
uploadedFiles += "\n${file}"
}
}
}
}

stage('Updating S3 Push Record') {
steps {
script {
echo "starting s3 push .........................."
def s3Path = "s3://beckn-frontend-assets/beckn/passculture/user/images/dummy.png"
sh ("aws s3 cp beckn/passculture/user/images/dummy2.png ${s3Path}")
env.SUMMARY = "Files Uploaded: ${uploadedFiles == '' ? 'NA' : uploadedFiles}"
sh "git remote set-url origin git@github.com:nammayatri/asset-store.git"
sh "git checkout ${BRANCH_NAME}"
sh "echo ${GIT_COMMIT} > s3LastCommitPush.txt"
sh "git add s3LastCommitPush.txt"
sh "git commit -m \"[skip ci] ${SUMMARY}\""
sh "git push origin HEAD:${BRANCH_NAME}"
echo "${SUMMARY}"
}
}
}
Expand Down
File renamed without changes

0 comments on commit ae25a03

Please sign in to comment.