diff --git a/Jenkinsfile b/Jenkinsfile index 590e625..3170b50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,6 +43,14 @@ spec: mountPath: /root/.docker - name: harbor-config mountPath: /docker-config + - name: tester + image: golang:1.23-bookworm + command: + - cat + tty: true + volumeMounts: + - name: workspace-volume + mountPath: /home/jenkins/agent volumes: - name: docker-config-writable emptyDir: {} @@ -60,6 +68,10 @@ spec: """ } } + environment { + SUITE_NAME = 'soteria' + PUSHGATEWAY_URL = 'http://platform-quality-gateway.monitoring.svc.cluster.local:9091' + } stages { stage('Checkout') { steps { @@ -71,13 +83,23 @@ spec: container('builder') { sh ''' set -euo pipefail - apk add --no-cache bash git jq + apk add --no-cache bash git jq curl mkdir -p /root/.docker cp /docker-config/config.json /root/.docker/config.json ''' } } } + stage('Unit tests') { + steps { + container('tester') { + sh ''' + set -euo pipefail + go test ./... + ''' + } + } + } stage('Compute version') { steps { container('builder') { @@ -101,7 +123,9 @@ spec: seq 1 10 | while read _; do docker info && break || sleep 2 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 { + 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 </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 </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 { script { if (fileExists('build.env')) {