Skip to content

Commit 1fab3ee

Browse files
authored
[FSTORE-1702] Add base file for jenkins (#491)
* Add base file for jenkins * Trigger again * Try to fix the ci.Jenkinsfile * Test with agent * Blabla * Triiger * Fix the pipeline * apply some review * Trust * Trigger * Use yq * Trigger * Use filename extension * Fix inputs * Maybe numbers are strings * Change the host * Change the host * Automatic branch * Try to check if there are some cool env variables in jenkins * Weird * Crazy * Fix typo * Improve the jenkins ci * Fix inputs * Trigger ci * Trigger * try again * Fix inputs.json * Try the better way * Minor changes' * Wrap in step * Try to debug the pipeline * Remove ci jenkinsfile * Edit pipeline * Tests * Trigger again * Try the trigger * Missing bracket * Remove steps from post condition * Named argument * Remove the post condition to highlight the failure * Fix sh command * Fixed the wrong one * More is more * Printenv * Don't run post always * Remove post * Forgot to comment one step * Remove wrong quote * Redirect towards correct backend * Move to script and .github directory * Remove extra bracket * Consistent naming * Move cleanup * Try more declarative * Try more declarative * Fix json parsing * Try again * Wrong sha * Make it work * Var naming * Remove cleanup and declarative download * Post is weird * Query parameters test * Remove a quote * Add -G to apply query params * Query between times * Remove sha stuff * Sorted * Test * Test * Update CI * Missing tick * Why? * Test * Printenv * Check the loadtest PRs * Test again * Sleep 5 * Add workflow run_id when looking for a match * Test the loadtest PR * Try the workflow updated * Try and try * Minor cleanups * Remove head sha * cleanup inputs * Leave the PR on loadtest alone for now * Fix inputs * Use staging ip * Try triggering workflow from different branch * Fix labels inputs * Add junit parsing * Maybe 10s is a bit lwo * Remove extra * Remove results.xml system * Add loadtest PR back * Trigger * Set automatically same PR * Target correct endpoint * Concatenate labels if exist * Try again for labels * Test the labels * Fix * trigger again * Trigger again * Trigger happy * Trigger one more time * Move ci file + target correct ref branch + fix ref to main
1 parent fba6f04 commit 1fab3ee

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

.github/ci.Jenkinsfile

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
def WORKFLOW_RUN_ID = "0"
2+
def SHORT_SHA = ""
3+
def REF_LOADTEST_BRANCH = ""
4+
def WORKFLOW_RUN_URL = ""
5+
6+
pipeline("E2E workflows") {
7+
agent {
8+
label "local"
9+
}
10+
environment {
11+
GITHUB_TOKEN = credentials('990f5312-cd08-48ec-baf8-3b27ff551204')
12+
}
13+
stages {
14+
stage('Clone repository') {
15+
steps {
16+
checkout scm
17+
}
18+
}
19+
stage('Input parameters') {
20+
steps {
21+
script {
22+
SHORT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
23+
echo "Short sha: ${SHORT_SHA}"
24+
sh "bash .github/workflow_inputs.sh ${SHORT_SHA}"
25+
REF_LOADTEST_BRANCH = sh(script: "cat inputs.json | jq -r '.ref'", returnStdout: true).trim()
26+
echo "Ref loadtest branch: ${REF_LOADTEST_BRANCH}"
27+
}
28+
}
29+
}
30+
stage('Post webhook') {
31+
steps {
32+
script {
33+
def dispatch_response = sh(script: """curl -L -X POST -H "Accept: application/vnd.github+json" \
34+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
35+
-H "X-GitHub-Api-Version: 2022-11-28" \
36+
-d @inputs.json \
37+
https://api.github.com/repos/logicalclocks/loadtest/actions/workflows/e2e_small.yaml/dispatches""",
38+
returnStdout: true
39+
).trim()
40+
echo "Dispatch response: ${dispatch_response}"
41+
sh "rm inputs.json"
42+
}
43+
}
44+
}
45+
stage ('Find workflow run id') {
46+
steps {
47+
script {
48+
sleep 5
49+
TIME_AFTER_WORKFLOW_DISPATCH = sh(script: "date -u +%Y-%m-%dT%H:%M:%SZ", returnStdout: true).trim()
50+
WORKFLOW_RUN_ID = sh(script: """curl -L -X GET -G -H "Accept: application/vnd.github+json" \
51+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
52+
-H "X-GitHub-Api-Version: 2022-11-28" \
53+
-d "event=workflow_dispatch" -d "actor=HopsworksJenkins" -d "branch=${REF_LOADTEST_BRANCH}" \
54+
https://api.github.com/repos/logicalclocks/loadtest/actions/runs | jq -r '.workflow_runs[0].id'""", returnStdout: true).trim()
55+
echo "Workflow run id: ${WORKFLOW_RUN_ID}"
56+
}
57+
}
58+
}
59+
stage('Wait for github action workflow to complete') {
60+
steps {
61+
script {
62+
def status = "in_progress"
63+
while (status == "in_progress" || status == "queued") {
64+
sleep 60
65+
status = sh(script: """curl -L -X GET -H "Accept: application/vnd.github+json" \
66+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
67+
-H "X-GitHub-Api-Version: 2022-11-28" \
68+
https://api.github.com/repos/logicalclocks/loadtest/actions/runs/${WORKFLOW_RUN_ID} | jq -r '.status' """, returnStdout: true).trim()
69+
echo "Status: ${status}"
70+
}
71+
}
72+
}
73+
}
74+
stage('Download artifacts') {
75+
steps {
76+
script {
77+
def REPORT_URL = sh(
78+
script: """curl -L -H "Accept: application/vnd.github+json" \
79+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
80+
-H "X-GitHub-Api-Version: 2022-11-28" \
81+
https://api.github.com/repos/logicalclocks/loadtest/actions/runs/${WORKFLOW_RUN_ID}/artifacts \
82+
| jq -r '.artifacts[] | select(.name == "results_${WORKFLOW_RUN_ID}.xml") | .archive_download_url' """,
83+
returnStdout: true
84+
).trim()
85+
echo "Report url: ${REPORT_URL}"
86+
sh(
87+
script: """curl -L -H \"Accept: application/vnd.github+json\" \
88+
-H \"Authorization: Bearer ${GITHUB_TOKEN}\" \
89+
-H \"X-GitHub-Api-Version: 2022-11-28\" \
90+
-o results.zip "${REPORT_URL}" """
91+
)
92+
sh """if [ -f results.xml ]; then rm results.xml; fi && unzip results.zip && rm results.zip"""
93+
}
94+
}
95+
}
96+
}
97+
post {
98+
always {
99+
junit 'results.xml'
100+
}
101+
}
102+
}

.github/workflow_inputs.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SHORT_SHA=$1
5+
echo "" > inputs.yaml
6+
7+
8+
if [[ ${ghprbPullTitle} =~ (FSTORE-[0-9]+) || ${ghprbPullTitle} =~ (HWORKS-[0-9]+) ]]; then
9+
captured_string=${BASH_REMATCH[1]}
10+
echo "Found JIRA ticket: ${captured_string}, checking for corresponding pr in loadtest repo"
11+
loadtest_prs=$(curl -L -G \
12+
-H "Accept: application/vnd.github+json" \
13+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
14+
-H "X-GitHub-Api-Version: 2022-11-28" \
15+
-d "state=open" \
16+
https://api.github.com/repos/logicalclocks/loadtest/pulls)
17+
18+
loadtest_branch=$(echo "${loadtest_prs}" | jq -r --arg captured_string ${captured_string} '.[] | select(.title | contains($captured_string)) | .head.ref')
19+
minikube_ip=$(echo "${loadtest_prs}" | jq -r --arg captured_string ${captured_string} '.[] | select(.title | contains($captured_string)) | .labels[] | select(.name | contains("10.87.")) | .name')
20+
labels=$(echo "${loadtest_prs}" | jq -r --arg captured_string ${captured_string} '.[] | select(.title | contains($captured_string)) | .labels[] | select(.name | contains("e2e")) | .name' | paste -sd ",")
21+
fi
22+
23+
if [ -z "${loadtest_branch}" ]; then
24+
echo "No corresponding pr found in loadtest repo, using main branch"
25+
loadtest_branch="main"
26+
else
27+
echo "Found loadtest branch: ${loadtest_branch}"
28+
fi
29+
30+
if [ -z "${minikube_ip}" ]; then
31+
echo "No minikube ip found in labels, using default staging cluster"
32+
minikube_ip="stagingmain.devnet.hops.works" # Make it domain name instead of ip
33+
else
34+
echo "Found minikube ip in loadtest PR labels: ${minikube_ip}"
35+
fi
36+
37+
if [ -z "${labels}" ]; then
38+
echo "No labels found, using default e2e_small"
39+
labels="e2e_small"
40+
else
41+
echo "Found labels: ${labels}"
42+
fi
43+
44+
# .ref is the name of the branch where the workflow dispatch will be sent.
45+
yq '.ref = "main"' -i inputs.yaml
46+
47+
yq '.inputs.max_parallel = "5"' -i inputs.yaml
48+
hopsworks_domain=$minikube_ip yq '.inputs.hopsworks_domain = strenv(hopsworks_domain)' -i inputs.yaml
49+
labels=$labels yq '.inputs.labels = strenv(labels)' -i inputs.yaml
50+
hopsworks_api_branch=${ghprbSourceBranch} yq '.inputs.hopsworks_api_branch = strenv(hopsworks_api_branch)' -i inputs.yaml
51+
loadtest_branch=${loadtest_branch} yq '.inputs.loadtest_head_ref = strenv(loadtest_branch)' -i inputs.yaml
52+
short_sha=$SHORT_SHA yq '.inputs.short_sha = strenv(short_sha)' -i inputs.yaml
53+
user_repo_api=${ghprbPullAuthorLogin} yq '.inputs.user_repo_api = strenv(user_repo_api)' -i inputs.yaml
54+
55+
yq -o=json inputs.yaml > inputs.json
56+
cat inputs.json

0 commit comments

Comments
 (0)