Skip to content

Commit 518a054

Browse files
committed
chore(build): check sonatype auth beforehand
1 parent bbdc0b7 commit 518a054

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

.gitlab-ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,32 @@ default:
186186
after_script:
187187
- *cgroup_info
188188

189+
# Checks and fail early if central credentials are incorrect, indeed, when a new token is generated
190+
# on the central publisher protal, it invalidates the old one. This checks prevents going further.
191+
# See https://datadoghq.atlassian.net/wiki/x/Oog5OgE
192+
pre-release-checks:
193+
image: ghcr.io/datadog/dd-trace-java-docker-build:${BUILDER_IMAGE_VERSION_PREFIX}base
194+
stage: .pre
195+
rules:
196+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
197+
when: on_success
198+
allow_failure: false
199+
script:
200+
- |
201+
SONATYPE_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
202+
SONATYPE_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
203+
# See https://central.sonatype.org/publish/publish-portal-api/
204+
# 15e0cbbb-deff-421e-9e02-296a24d0cada is deployment, any deployment id listed in central work, the idea is to check whether the token can authenticate
205+
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" | base64)"
206+
if [ $? -ne 0 ]; then
207+
echo "Failed to authenticate against central. Check credentials, see https://datadoghq.atlassian.net/wiki/x/Oog5OgE"
208+
exit 1
209+
fi
210+
189211
build:
212+
needs:
213+
- job: pre-release-checks
214+
optional: true
190215
extends: .gradle_build
191216
variables:
192217
BUILD_CACHE_POLICY: push

0 commit comments

Comments
 (0)