Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test framework build pipeline #1346

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .pipelines/azure_pipeline_testframework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
#

trigger:
batch: true
branches:
include:
- ci_prod

pr:
branches:
include:
- ci_prod

jobs:
- deployment: Testkube
environment: container-insights
displayName: "Test: run testkube tests"
pool:
name: Azure-Pipelines-CI-Test-EO
variables:
skipComponentGovernanceDetection: true
strategy:
runOnce:
deploy:
steps:
- checkout: self
persistCredentials: true

- bash: |
wget -qO - https://repo.testkube.io/key.pub | sudo apt-key add -
suyadav1 marked this conversation as resolved.
Show resolved Hide resolved
echo "deb https://repo.testkube.io/linux linux main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y testkube=1.14.2
ganga1980 marked this conversation as resolved.
Show resolved Hide resolved
workingDirectory: $(Build.SourcesDirectory)
displayName: "Install testkube CLI"

- task: AzureCLI@1
suyadav1 marked this conversation as resolved.
Show resolved Hide resolved
displayName: Get kubeconfig
inputs:
azureSubscription: 'ContainerInsights_Build_Subscription'
scriptLocation: 'inlineScript'
inlineScript: 'az aks get-credentials -g $(RESOURCE_GROUP) -n $(CLUSTER_NAME)'

- bash: |
envsubst < ./testkube/testkube-test-crs.yaml > ./testkube/testkube-test-crs-$(CLUSTER_NAME).yaml
kubectl apply -f ./testkube/api-server-permissions.yaml
kubectl apply -f ./testkube/testkube-test-crs-$(CLUSTER_NAME).yaml
exit 0
workingDirectory: $(Build.SourcesDirectory)/test/
displayName: "Apply TestKube CRs and pod/service monitors"

- bash: |
sleep 120
displayName: "Wait for cluster to be ready"

- bash: |
# Run the full test suite
kubectl testkube run testsuite e2e-tests-merge --verbose

# Get the current id of the test suite now running
execution_id=$(kubectl testkube get testsuiteexecutions --test-suite e2e-tests-merge --limit 1 | grep e2e-tests | awk '{print $1}')
suyadav1 marked this conversation as resolved.
Show resolved Hide resolved

# Watch until the all the tests in the test suite finish
kubectl testkube watch testsuiteexecution $execution_id

# Get the results as a formatted json file
kubectl testkube get testsuiteexecution $execution_id --output json > testkube-results.json

# For any test that has failed, print out the Ginkgo logs
if [[ $(jq -r '.status' testkube-results.json) == "failed" ]]; then

# Get each test name and id that failed
jq -r '.executeStepResults[].execute[] | select(.execution.executionResult.status=="failed") | "\(.execution.testName) \(.execution.id)"' testkube-results.json | while read line; do
testName=$(echo $line | cut -d ' ' -f 1)
id=$(echo $line | cut -d ' ' -f 2)
echo "Test $testName failed. Test ID: $id"

# Get the Ginkgo logs of the test
kubectl testkube get execution $id > out 2>error.log

# Remove superfluous logs of everything before the last occurence of 'go downloading'.
# The actual errors can be viewed from the ADO run, instead of needing to view the testkube dashboard.
cat error.log | tac | awk '/go: downloading/ {exit} 1' | tac
done

# Explicitly fail the ADO task since at least one test failed
exit 1
fi
workingDirectory: $(Build.SourcesDirectory)
displayName: "Run tests"
Loading