Skip to content

Commit

Permalink
US-415270 Migrate automation repo from bintray to test GitHub Pages (#…
Browse files Browse the repository at this point in the history
…281)

* Added Jenkinsfile

* US-415270 Migrate automation repo from bintray to test GitHub Pages

* Validate artefact push against testing repo

* Validate artefact push against testing repo

* US-415270 Refactored to use credentials for username

Co-authored-by: arugm <Madhuri.Arugula@in.pega.com>
  • Loading branch information
MadhuriArugula and arugm authored May 4, 2021
1 parent 9d81f1c commit 7692c05
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env groovy
def bintrayautomation = "bintrayautomation"
def labels = ""
def bintrayPackageVersion = "1.0.0"
def curlSuccessStatus = '{"message":"success"}'

node {
stage("Init"){
Expand Down Expand Up @@ -31,39 +28,33 @@ node {
branchName = "${scmVars.GIT_BRANCH}"
packageName = currentBuild.displayName
prNumber = "${env.BRANCH_NAME}".split("-")[1]
chartVersion = "${prNumber}.${env.BUILD_NUMBER}"

// Perform Chart packaging
sh "helm dependency update ./charts/pega/"
sh "helm dependency update ./charts/addons/"
sh "curl -o index.yaml https://dl.bintray.com/pegasystems/helm-test-automation/index.yaml"
sh "helm package --version ${prNumber}.${env.BUILD_NUMBER} ./charts/pega/"
sh "helm package --version ${prNumber}.${env.BUILD_NUMBER} ./charts/addons/"
sh "helm repo index --merge index.yaml --url https://dl.bintray.com/pegasystems/helm-test-automation/ ."
sh "cat index.yaml"
sh "helm dependency update ./charts/backingservices/"
sh "helm package --version ${chartVersion} ./charts/pega/"
sh "helm package --version ${chartVersion} ./charts/addons/"
sh "helm package --version ${chartVersion} ./charts/backingservices/"

// Publish helm charts to test-automation repository
withCredentials([usernamePassword(credentialsId: "bintrayautomation",
passwordVariable: 'BINTRAY_APIKEY', usernameVariable: 'BINTRAY_USERNAME')]) {
chartVersion = "${prNumber}.${env.BUILD_NUMBER}"
pega_chartName = "pega-${chartVersion}.tgz"
addons_chartName = "addons-${chartVersion}.tgz"
DELETE_STATUS_CODE = sh(script: "curl -X DELETE -u${BINTRAY_USERNAME}:${BINTRAY_APIKEY} https://api.bintray.com/content/pegasystems/helm-test-automation/index.yaml --write-out '%{http_code}'", returnStdout: true).trim()
PEGA_STATUS_CODE = sh(script: "curl -T ${pega_chartName} -u${BINTRAY_USERNAME}:${BINTRAY_APIKEY} https://api.bintray.com/content/pegasystems/helm-test-automation/helm-test-automation/${bintrayPackageVersion}/ --write-out '%{http_code}'", returnStdout: true).trim()
ADDONS_STATUS_CODE = sh(script: "curl -T ${addons_chartName} -u${BINTRAY_USERNAME}:${BINTRAY_APIKEY} https://api.bintray.com/content/pegasystems/helm-test-automation/helm-test-automation/${bintrayPackageVersion}/ --write-out '%{http_code}' ", returnStdout: true).trim()
UPDATE_STATUS_CODE = sh(script: "curl -T index.yaml -u${BINTRAY_USERNAME}:${BINTRAY_APIKEY} https://api.bintray.com/content/pegasystems/helm-test-automation/helm-test-automation/${bintrayPackageVersion}/ --write-out '%{http_code}'", returnStdout: true).trim()
PUBLISH_STATUS_CODE = sh(script: "curl -X POST -u${BINTRAY_USERNAME}:${BINTRAY_APIKEY} https://api.bintray.com/content/pegasystems/helm-test-automation/helm-test-automation/${bintrayPackageVersion}/publish --write-out '%{http_code}'", returnStdout: true).trim()
echo "DELETE_STATUS_CODE-- ${DELETE_STATUS_CODE}"
echo "PEGA_STATUS_CODE-- ${PEGA_STATUS_CODE}"
echo "ADDONS_STATUS_CODE-- ${ADDONS_STATUS_CODE}"
echo "UPDATE_STATUS_CODE-- ${UPDATE_STATUS_CODE}"
echo "PUBLISH_STATUS_CODE-- ${PUBLISH_STATUS_CODE}"
// Publish helm charts to test-automation GitHub Pages
withCredentials([usernamePassword(credentialsId: "helmautomation",
passwordVariable: 'AUTOMATION_APIKEY', usernameVariable: 'AUTOMATION_USERNAME')]) {

if ( "${DELETE_STATUS_CODE}" != "${curlSuccessStatus}"+"200" || "${PEGA_STATUS_CODE}" != "${curlSuccessStatus}"+"201" || "${ADDONS_STATUS_CODE}" != "${curlSuccessStatus}"+"201"
|| "${UPDATE_STATUS_CODE}" != "${curlSuccessStatus}"+"201" || "${PUBLISH_STATUS_CODE}" != '{"files":3}'+"200" ) {
currentBuild.result = 'FAILURE'
pullRequest.comment("Unable to publish helm charts to bintray repository. Please retry")
error "This pipeline stops here! Unable to perform helm charts publish to bintray repository."
sh "git clone https://${AUTOMATION_USERNAME}:${AUTOMATION_APIKEY}@github.com/pegaautomationuser/helmcharts.git --branch=gh-pages gh-pages"
sh "mv pega-${chartVersion}.tgz gh-pages/"
sh "mv addons-${chartVersion}.tgz gh-pages/"
sh "mv backingservices-${chartVersion}.tgz gh-pages/"
dir("gh-pages") {
sh "helm repo index --merge index.yaml --url https://pegaautomationuser.github.io/helmcharts/ ."
sh "git config user.email pegaautomationuser@gmail.com"
sh "git config user.name ${AUTOMATION_USERNAME}"
sh "git add ."
sh "git commit -m \"Jenkins build to publish test artefacts of version ${chartVersion}\""
sh "git push -u origin gh-pages --force"
}

}
}

Expand Down

0 comments on commit 7692c05

Please sign in to comment.