ci: fix harbor auth and publish go test totals
This commit is contained in:
parent
fe7295d629
commit
cccbd6ebd2
70
Jenkinsfile
vendored
70
Jenkinsfile
vendored
@ -55,11 +55,10 @@ spec:
|
||||
- name: docker-config-writable
|
||||
emptyDir: {}
|
||||
- name: dind-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: jenkins-dind-cache
|
||||
emptyDir: {}
|
||||
- name: harbor-config
|
||||
secret:
|
||||
secretName: harbor-bstein-robot
|
||||
secretName: harbor-robot-pipeline
|
||||
items:
|
||||
- key: .dockerconfigjson
|
||||
path: config.json
|
||||
@ -95,7 +94,31 @@ spec:
|
||||
container('tester') {
|
||||
sh '''
|
||||
set -eu
|
||||
go test ./...
|
||||
apt-get update >/dev/null
|
||||
apt-get install -y --no-install-recommends jq >/dev/null
|
||||
mkdir -p build
|
||||
set +e
|
||||
go test -json ./... > build/go-test.json
|
||||
test_rc=$?
|
||||
set -e
|
||||
tests_total="$(jq -s '[.[] | select(.Test != null and (.Action=="pass" or .Action=="fail" or .Action=="skip"))] | length' build/go-test.json)"
|
||||
tests_failed="$(jq -s '[.[] | select(.Test != null and .Action=="fail")] | length' build/go-test.json)"
|
||||
tests_skipped="$(jq -s '[.[] | select(.Test != null and .Action=="skip")] | length' build/go-test.json)"
|
||||
tests_errors="$(jq -s '[.[] | select(.Test == null and .Action=="fail")] | length' build/go-test.json)"
|
||||
tests_passed=$((tests_total - tests_failed - tests_skipped))
|
||||
if [ "${tests_passed}" -lt 0 ]; then
|
||||
tests_passed=0
|
||||
fi
|
||||
cat > build/test-summary.json <<EOF
|
||||
{
|
||||
"tests": ${tests_total},
|
||||
"passed": ${tests_passed},
|
||||
"failed": ${tests_failed},
|
||||
"errors": ${tests_errors},
|
||||
"skipped": ${tests_skipped}
|
||||
}
|
||||
EOF
|
||||
exit "${test_rc}"
|
||||
'''
|
||||
}
|
||||
}
|
||||
@ -133,15 +156,18 @@ spec:
|
||||
stage('Build & push image') {
|
||||
steps {
|
||||
container('builder') {
|
||||
sh '''
|
||||
set -eu
|
||||
VERSION_TAG=$(cut -d= -f2 build.env)
|
||||
docker buildx build --platform linux/arm64 \
|
||||
--provenance=false \
|
||||
--tag registry.bstein.dev/bstein/soteria:${VERSION_TAG} \
|
||||
--tag registry.bstein.dev/bstein/soteria:latest \
|
||||
--push .
|
||||
'''
|
||||
withCredentials([usernamePassword(credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
|
||||
sh '''
|
||||
set -eu
|
||||
VERSION_TAG=$(cut -d= -f2 build.env)
|
||||
printf '%s' "${HARBOR_PASSWORD}" | docker login registry.bstein.dev -u "${HARBOR_USERNAME}" --password-stdin
|
||||
docker buildx build --platform linux/arm64 \
|
||||
--provenance=false \
|
||||
--tag registry.bstein.dev/bstein/soteria:${VERSION_TAG} \
|
||||
--tag registry.bstein.dev/bstein/soteria:latest \
|
||||
--push .
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,10 +194,19 @@ spec:
|
||||
ok_count="$(fetch_counter ok)"
|
||||
failed_count="$(fetch_counter failed)"
|
||||
ok_count=$((ok_count + 1))
|
||||
tests_passed="$(jq -r '.passed // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_failed="$(jq -r '.failed // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_errors="$(jq -r '.errors // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_skipped="$(jq -r '.skipped // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
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}
|
||||
# TYPE soteria_quality_gate_tests_total gauge
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="passed"} ${tests_passed}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="failed"} ${tests_failed}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="error"} ${tests_errors}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="skipped"} ${tests_skipped}
|
||||
METRICS
|
||||
'''
|
||||
}
|
||||
@ -197,10 +232,19 @@ METRICS
|
||||
ok_count="$(fetch_counter ok)"
|
||||
failed_count="$(fetch_counter failed)"
|
||||
failed_count=$((failed_count + 1))
|
||||
tests_passed="$(jq -r '.passed // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_failed="$(jq -r '.failed // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_errors="$(jq -r '.errors // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
tests_skipped="$(jq -r '.skipped // 0' build/test-summary.json 2>/dev/null || echo 0)"
|
||||
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}
|
||||
# TYPE soteria_quality_gate_tests_total gauge
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="passed"} ${tests_passed}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="failed"} ${tests_failed}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="error"} ${tests_errors}
|
||||
soteria_quality_gate_tests_total{suite="${suite}",result="skipped"} ${tests_skipped}
|
||||
METRICS
|
||||
'''
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user