Skip to content

Commit ace46a4

Browse files
MadhuriArugulaarugm
andauthored
Automate Integration tests for PR's (#192)
* Integrate repo for automation testing * Update Jenkinsfile * Update Jenkinsfile * Changing node for job execution Co-authored-by: arugm <[email protected]>
1 parent fe6b557 commit ace46a4

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

Jenkinsfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env groovy
2+
def bintrayautomation = "bintrayautomation"
3+
def labels = ""
4+
def bintrayPackageVersion = "1.0.0"
5+
def curlSuccessStatus = '{"message":"success"}'
6+
7+
node {
8+
stage("Init"){
9+
if (env.CHANGE_ID) {
10+
pullRequest.labels.each{
11+
echo "label: $it"
12+
validateProviderLabel(it)
13+
labels += "$it,"
14+
}
15+
labels = labels.substring(0,labels.length()-1)
16+
echo "PR labels -> $labels"
17+
// Comment on PR about the text execution
18+
pullRequest.comment("Starting ${env.BRANCH_NAME} validation on -> $labels")
19+
sh "curl -fsSL -o helm-v3.2.4-linux-amd64.tar.gz https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz"
20+
sh "tar -zxvf helm-v3.2.4-linux-amd64.tar.gz"
21+
sh "mv linux-amd64/helm /usr/local/bin/helm"
22+
} else {
23+
currentBuild.result = 'ABORTED'
24+
throw new Exception("Aborting as this is not a PR job")
25+
}
26+
}
27+
stage ("Checkout and Package Charts") {
28+
29+
// Checkout PR Code
30+
def scmVars = checkout scm
31+
branchName = "${scmVars.GIT_BRANCH}"
32+
packageName = currentBuild.displayName
33+
prNumber = "${env.BRANCH_NAME}".split("-")[1]
34+
35+
// Perform Chart packaging
36+
sh "helm dependency update ./charts/pega/"
37+
sh "helm dependency update ./charts/addons/"
38+
sh "curl -o index.yaml https://dl.bintray.com/pegasystems/helm-test-automation/index.yaml"
39+
sh "helm package --version ${prNumber}.${env.BUILD_NUMBER} ./charts/pega/"
40+
sh "helm package --version ${prNumber}.${env.BUILD_NUMBER} ./charts/addons/"
41+
sh "helm repo index --merge index.yaml --url https://dl.bintray.com/pegasystems/helm-test-automation/ ."
42+
sh "cat index.yaml"
43+
44+
// Publish helm charts to test-automation repository
45+
withCredentials([usernamePassword(credentialsId: "bintrayautomation",
46+
passwordVariable: 'BINTRAY_APIKEY', usernameVariable: 'BINTRAY_USERNAME')]) {
47+
chartVersion = "${prNumber}.${env.BUILD_NUMBER}"
48+
pega_chartName = "pega-${chartVersion}.tgz"
49+
addons_chartName = "addons-${chartVersion}.tgz"
50+
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()
51+
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()
52+
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()
53+
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()
54+
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()
55+
echo "DELETE_STATUS_CODE-- ${DELETE_STATUS_CODE}"
56+
echo "PEGA_STATUS_CODE-- ${PEGA_STATUS_CODE}"
57+
echo "ADDONS_STATUS_CODE-- ${ADDONS_STATUS_CODE}"
58+
echo "UPDATE_STATUS_CODE-- ${UPDATE_STATUS_CODE}"
59+
echo "PUBLISH_STATUS_CODE-- ${PUBLISH_STATUS_CODE}"
60+
61+
if ( "${DELETE_STATUS_CODE}" != "${curlSuccessStatus}"+"200" || "${PEGA_STATUS_CODE}" != "${curlSuccessStatus}"+"201" || "${ADDONS_STATUS_CODE}" != "${curlSuccessStatus}"+"201"
62+
|| "${UPDATE_STATUS_CODE}" != "${curlSuccessStatus}"+"201" || "${PUBLISH_STATUS_CODE}" != '{"files":3}'+"200" ) {
63+
currentBuild.result = 'FAILURE'
64+
pullRequest.comment("Unable to publish helm charts to bintray repository. Please retry")
65+
error "This pipeline stops here! Unable to perform helm charts publish to bintray repository."
66+
}
67+
}
68+
}
69+
70+
stage("Setup Cluster and Execute Tests") {
71+
72+
jobMap = [:]
73+
jobMap["job"] = "../kubernetes-test-orchestrator/master"
74+
jobMap["parameters"] = [
75+
string(name: 'PROVIDERS', value: labels),
76+
string(name: 'WEB_READY_IMAGE_NAME', value: ""),
77+
string(name: 'HELM_CHART_VERSION', value: chartVersion),
78+
]
79+
jobMap["propagate"] = true
80+
jobMap["quietPeriod"] = 0
81+
resultWrapper = build jobMap
82+
currentBuild.result = resultWrapper.result
83+
}
84+
}
85+
86+
def validateProviderLabel(String provider){
87+
def validProviders = ["integ-all","integ-eks","integ-gke","integ-aks"]
88+
def failureMessage = "Invalid provider label - ${provider}. valid labels are ${validProviders}"
89+
if(!validProviders.contains(provider)){
90+
currentBuild.result = 'FAILURE'
91+
pullRequest.comment("${failureMessage}")
92+
throw new Exception("${failureMessage}")
93+
}
94+
}

0 commit comments

Comments
 (0)