Skip to content

Commit 38786dc

Browse files
authored
Added test framework build pipeline (#1346)
* Added test framework build pipeline * Added variables for RG and cluster name
1 parent cf803fc commit 38786dc

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Starter pipeline
2+
# Start with a minimal pipeline that you can customize to build and deploy your code.
3+
# Add steps that build, run tests, deploy, and more:
4+
# https://aka.ms/yaml
5+
#
6+
7+
trigger:
8+
batch: true
9+
branches:
10+
include:
11+
- ci_prod
12+
13+
pr:
14+
branches:
15+
include:
16+
- ci_prod
17+
18+
jobs:
19+
- deployment: Testkube
20+
environment: container-insights
21+
displayName: "Test: run testkube tests"
22+
pool:
23+
name: Azure-Pipelines-CI-Test-EO
24+
variables:
25+
skipComponentGovernanceDetection: true
26+
strategy:
27+
runOnce:
28+
deploy:
29+
steps:
30+
- checkout: self
31+
persistCredentials: true
32+
33+
- bash: |
34+
wget -qO - https://repo.testkube.io/key.pub | sudo apt-key add -
35+
echo "deb https://repo.testkube.io/linux linux main" | sudo tee -a /etc/apt/sources.list
36+
sudo apt-get update
37+
sudo apt-get install -y testkube=1.14.2
38+
workingDirectory: $(Build.SourcesDirectory)
39+
displayName: "Install testkube CLI"
40+
41+
- task: AzureCLI@1
42+
displayName: Get kubeconfig
43+
inputs:
44+
azureSubscription: 'ContainerInsights_Build_Subscription'
45+
scriptLocation: 'inlineScript'
46+
inlineScript: 'az aks get-credentials -g $(RESOURCE_GROUP) -n $(CLUSTER_NAME)'
47+
48+
- bash: |
49+
envsubst < ./testkube/testkube-test-crs.yaml > ./testkube/testkube-test-crs-$(CLUSTER_NAME).yaml
50+
kubectl apply -f ./testkube/api-server-permissions.yaml
51+
kubectl apply -f ./testkube/testkube-test-crs-$(CLUSTER_NAME).yaml
52+
exit 0
53+
workingDirectory: $(Build.SourcesDirectory)/test/
54+
displayName: "Apply TestKube CRs and pod/service monitors"
55+
56+
- bash: |
57+
sleep 120
58+
displayName: "Wait for cluster to be ready"
59+
60+
- bash: |
61+
# Run the full test suite
62+
kubectl testkube run testsuite e2e-tests-merge --verbose
63+
64+
# Get the current id of the test suite now running
65+
execution_id=$(kubectl testkube get testsuiteexecutions --test-suite e2e-tests-merge --limit 1 | grep e2e-tests | awk '{print $1}')
66+
67+
# Watch until the all the tests in the test suite finish
68+
kubectl testkube watch testsuiteexecution $execution_id
69+
70+
# Get the results as a formatted json file
71+
kubectl testkube get testsuiteexecution $execution_id --output json > testkube-results.json
72+
73+
# For any test that has failed, print out the Ginkgo logs
74+
if [[ $(jq -r '.status' testkube-results.json) == "failed" ]]; then
75+
76+
# Get each test name and id that failed
77+
jq -r '.executeStepResults[].execute[] | select(.execution.executionResult.status=="failed") | "\(.execution.testName) \(.execution.id)"' testkube-results.json | while read line; do
78+
testName=$(echo $line | cut -d ' ' -f 1)
79+
id=$(echo $line | cut -d ' ' -f 2)
80+
echo "Test $testName failed. Test ID: $id"
81+
82+
# Get the Ginkgo logs of the test
83+
kubectl testkube get execution $id > out 2>error.log
84+
85+
# Remove superfluous logs of everything before the last occurence of 'go downloading'.
86+
# The actual errors can be viewed from the ADO run, instead of needing to view the testkube dashboard.
87+
cat error.log | tac | awk '/go: downloading/ {exit} 1' | tac
88+
done
89+
90+
# Explicitly fail the ADO task since at least one test failed
91+
exit 1
92+
fi
93+
workingDirectory: $(Build.SourcesDirectory)
94+
displayName: "Run tests"

0 commit comments

Comments
 (0)