ci: add unit test gate and pushgateway publishing
This commit is contained in:
parent
ca5961990a
commit
8639df941a
86
Jenkinsfile
vendored
86
Jenkinsfile
vendored
@ -43,6 +43,14 @@ spec:
|
|||||||
mountPath: /root/.docker
|
mountPath: /root/.docker
|
||||||
- name: harbor-config
|
- name: harbor-config
|
||||||
mountPath: /docker-config
|
mountPath: /docker-config
|
||||||
|
- name: tester
|
||||||
|
image: golang:1.23-bookworm
|
||||||
|
command:
|
||||||
|
- cat
|
||||||
|
tty: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace-volume
|
||||||
|
mountPath: /home/jenkins/agent
|
||||||
volumes:
|
volumes:
|
||||||
- name: docker-config-writable
|
- name: docker-config-writable
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
@ -60,6 +68,10 @@ spec:
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
environment {
|
||||||
|
SUITE_NAME = 'soteria'
|
||||||
|
PUSHGATEWAY_URL = 'http://platform-quality-gateway.monitoring.svc.cluster.local:9091'
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
@ -71,13 +83,23 @@ spec:
|
|||||||
container('builder') {
|
container('builder') {
|
||||||
sh '''
|
sh '''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
apk add --no-cache bash git jq
|
apk add --no-cache bash git jq curl
|
||||||
mkdir -p /root/.docker
|
mkdir -p /root/.docker
|
||||||
cp /docker-config/config.json /root/.docker/config.json
|
cp /docker-config/config.json /root/.docker/config.json
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Unit tests') {
|
||||||
|
steps {
|
||||||
|
container('tester') {
|
||||||
|
sh '''
|
||||||
|
set -euo pipefail
|
||||||
|
go test ./...
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('Compute version') {
|
stage('Compute version') {
|
||||||
steps {
|
steps {
|
||||||
container('builder') {
|
container('builder') {
|
||||||
@ -101,7 +123,9 @@ spec:
|
|||||||
seq 1 10 | while read _; do
|
seq 1 10 | while read _; do
|
||||||
docker info && break || sleep 2
|
docker info && break || sleep 2
|
||||||
done
|
done
|
||||||
docker buildx create --name bstein-builder --driver docker-container --bootstrap --use
|
BUILDER_NAME="soteria-${BUILD_NUMBER}"
|
||||||
|
docker buildx rm "${BUILDER_NAME}" >/dev/null 2>&1 || true
|
||||||
|
docker buildx create --name "${BUILDER_NAME}" --driver docker-container --bootstrap --use
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,6 +147,64 @@ spec:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
|
success {
|
||||||
|
container('builder') {
|
||||||
|
sh '''
|
||||||
|
set -euo pipefail
|
||||||
|
suite="${SUITE_NAME}"
|
||||||
|
gateway="${PUSHGATEWAY_URL}"
|
||||||
|
fetch_counter() {
|
||||||
|
status="$1"
|
||||||
|
line="$(curl -fsS "${gateway}/metrics" 2>/dev/null | awk -v suite="${suite}" -v status="${status}" '
|
||||||
|
/^platform_quality_gate_runs_total\{/ {
|
||||||
|
if (index($0, "job=\\"platform-quality-ci\\"") && index($0, "suite=\\"" suite "\\"") && index($0, "status=\\"" status "\\"")) {
|
||||||
|
print $2
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' || true)"
|
||||||
|
[ -n "${line}" ] && printf '%s\n' "${line}" || printf '0\n'
|
||||||
|
}
|
||||||
|
ok_count="$(fetch_counter ok)"
|
||||||
|
failed_count="$(fetch_counter failed)"
|
||||||
|
ok_count=$((ok_count + 1))
|
||||||
|
cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null
|
||||||
|
# TYPE platform_quality_gate_runs_total counter
|
||||||
|
platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count}
|
||||||
|
platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count}
|
||||||
|
METRICS
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
container('builder') {
|
||||||
|
sh '''
|
||||||
|
set -euo pipefail
|
||||||
|
suite="${SUITE_NAME}"
|
||||||
|
gateway="${PUSHGATEWAY_URL}"
|
||||||
|
fetch_counter() {
|
||||||
|
status="$1"
|
||||||
|
line="$(curl -fsS "${gateway}/metrics" 2>/dev/null | awk -v suite="${suite}" -v status="${status}" '
|
||||||
|
/^platform_quality_gate_runs_total\{/ {
|
||||||
|
if (index($0, "job=\\"platform-quality-ci\\"") && index($0, "suite=\\"" suite "\\"") && index($0, "status=\\"" status "\\"")) {
|
||||||
|
print $2
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' || true)"
|
||||||
|
[ -n "${line}" ] && printf '%s\n' "${line}" || printf '0\n'
|
||||||
|
}
|
||||||
|
ok_count="$(fetch_counter ok)"
|
||||||
|
failed_count="$(fetch_counter failed)"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null
|
||||||
|
# TYPE platform_quality_gate_runs_total counter
|
||||||
|
platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count}
|
||||||
|
platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count}
|
||||||
|
METRICS
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
always {
|
always {
|
||||||
script {
|
script {
|
||||||
if (fileExists('build.env')) {
|
if (fileExists('build.env')) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user