Skip to content

Commit 537e83a

Browse files
committed
[RelEng] Migrate Maven publication to new Central Portal API
1 parent 53a75be commit 537e83a

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

JenkinsJobs/Releng/FOLDER.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ then deploys the artifacts for <code>Eclipse-Platform</code>, <code>JDT</code>,
1515
Snapshots are deployed to <a href="https://repo.eclipse.org/content/repositories/eclipse-snapshots/">https://repo.eclipse.org/content/repositories/eclipse-snapshots/</a>.
1616
</li>
1717
<li>
18-
Releases are deployed to <a href="https://repo1.maven.org/maven2/org/eclipse/">Maven central</a> by deploying to a <a href="https://oss.sonatype.org/#stagingRepositories">staging repository</a>.
18+
Releases are published to <a href="https://repo1.maven.org/maven2/org/eclipse/">Maven central</a> through the <a href="https://central.sonatype.org/publish/publish-portal-guide/">Central Portal</a>.
1919
</li>
2020
</ul>
2121
<p>
@@ -31,7 +31,7 @@ If left blank (not recommended), the latest I-build is deployed.
3131
Snapshots are deployed to <a href="https://repo.eclipse.org/content/repositories/eclipse-snapshots/">https://repo.eclipse.org/content/repositories/eclipse-snapshots/</a>.
3232
</li>
3333
<li>
34-
Releases are deployed to <a href="https://repo1.maven.org/maven2/org/eclipse/">Maven central</a> by deploying to a <a href="https://oss.sonatype.org/#stagingRepositories">staging repository</a>.
34+
Releases are published to <a href="https://repo1.maven.org/maven2/org/eclipse/">Maven central</a> through the <a href="https://central.sonatype.org/publish/publish-portal-guide/">Central Portal</a>.
3535
</li>
3636
</ul>
3737
''')

JenkinsJobs/Releng/deployToMaven.jenkinsfile

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pipeline {
9595
stage('Deploy project to Maven'){
9696
environment {
9797
SETTINGS = "/home/jenkins/.m2/settings-deploy-ossrh-${PROJECT == 'platform' ? 'releng': PROJECT}.xml"
98+
SONATYPE_BEARER_TOKEN = credentials("central-sonatype-bearer-token-${PROJECT}")
9899
// The location of the temporarily file that contains the secret file content
99100
// (see https://www.jenkins.io/doc/book/pipeline/syntax/#supported-credentials-type):
100101
KEYRING = credentials("secret-subkeys-${PROJECT == 'platform' ? 'releng': PROJECT}.asc")
@@ -109,8 +110,7 @@ pipeline {
109110
for pomFile in $(cat "${WORKSPACE}/artifacts-${PROJECT}.txt"); do
110111
set +x
111112
pomFolder=$(dirname ${pomFile})
112-
version=$(basename ${pomFolder})
113-
if [[ $version == *-SNAPSHOT ]]; then
113+
if [ "${DEPLOYMENT_TYPE}" != 'release' ]; then
114114
URL=https://repo.eclipse.org/content/repositories/eclipse-snapshots/
115115
REPO_ID=repo.eclipse.org # server-id in the settings.xml, used for authentication
116116
MAVEN_CENTRAL_URL=https://repo1.maven.org/maven2/${pomFolder%-SNAPSHOT}
@@ -119,8 +119,7 @@ pipeline {
119119
echo "The released version of file "${pomFile}" is already present at $MAVEN_CENTRAL_URL."
120120
fi
121121
else
122-
URL=https://oss.sonatype.org/service/local/staging/deploy/maven2/
123-
REPO_ID=ossrh # server-id in the settings.xml, used for authentication
122+
URL=file://$(pwd)
124123
MAVEN_CENTRAL_URL=https://repo1.maven.org/maven2/${pomFolder}
125124
echo "Checking ${MAVEN_CENTRAL_URL}"
126125
if curl --output /dev/null --silent --head --fail "$MAVEN_CENTRAL_URL"; then
@@ -160,6 +159,44 @@ pipeline {
160159
${SOURCES_ARG} ${JAVADOC_ARG}
161160
done
162161
'''
162+
script {
163+
if ("${DEPLOYMENT_TYPE}" == 'release') {
164+
// Documentation of the Central Portal Publisher API
165+
// - https://central.sonatype.org/publish/publish-portal-api
166+
// - https://central.sonatype.com/api-doc
167+
sh 'zip -r "${PROJECT}-artifacts.zip" "org/eclipse/${PROJECT}"'
168+
def deploymentId = sh(returnStdout: true, script: '''
169+
curl --request POST \
170+
--verbose \
171+
--header "Authorization: Bearer ${SONATYPE_BEARER_TOKEN}" \
172+
--header 'accept: text/plain' \
173+
--header 'Content-Type: multipart/form-data' \
174+
--form "bundle=@${PROJECT}-artifacts.zip" \
175+
'https://central.sonatype.com/api/v1/publisher/upload?publishingType=USER_MANAGED'
176+
''')
177+
writeFile(file: "${WORKSPACE}/deploymentId-${PROJECT}.txt", text: "${deploymentId}")
178+
waitUntil(initialRecurrencePeriod: 5_000) {
179+
// See https://central.sonatype.org/publish/publish-portal-api/#verify-status-of-the-deployment
180+
def deploymentStatusResponse = sh(returnStdout: true, script: """
181+
curl --request POST \
182+
--verbose \
183+
--header "Authorization: Bearer \${SONATYPE_BEARER_TOKEN}" \
184+
--header 'accept: application/json' \
185+
"https://central.sonatype.com/api/v1/publisher/status?id=${deploymentId}"
186+
""").trim()
187+
def deploymentStatus = readJSON(text: deploymentStatusResponse, returnPojo: true)
188+
if (deploymentStatus.deploymentState == 'VALIDATED' && !deploymentStatus.errors) {
189+
echo "Upload to Maven Central Portal successful:\n${groovy.json.JsonOutput.prettyPrint(deploymentStatusResponse)}"
190+
return true
191+
} else if(deploymentStatus.deploymentState == 'PENDING' || deploymentStatus.deploymentState == 'VALIDATING') {
192+
echo "Upload is being processed: ${deploymentStatus.deploymentState}"
193+
return false
194+
} else {
195+
error "Upload failed or has an unexpected status:\n${groovy.json.JsonOutput.prettyPrint(deploymentStatusResponse)}"
196+
}
197+
}
198+
}
199+
}
163200
}
164201
}
165202
}
@@ -171,7 +208,7 @@ pipeline {
171208
always {
172209
archiveArtifacts allowEmptyArchive: true, artifacts: '\
173210
repo/**, \
174-
coordinates*.txt, artifacts*.txt'
211+
coordinates*.txt, artifacts*.txt, deploymentId-*.txt'
175212
}
176213
failure {
177214
emailext subject: "Publication of Maven artifacts failed",

RELEASE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ The actual steps to release
112112
- Deploying to maven should happen by at least Tuesday before the release since there is up to a 24 hour delay for the maven mirrors.
113113
- Run the [Deploy to Maven](https://ci.eclipse.org/releng/job/Releng/job/deployToMaven/) job in Jenkins with the release build as `sourceRepository`.
114114
- About a minute after triggering the job, Jenkins will ask for confirmation on the console, if the specified build should really be deployed to Maven-Central staging.
115-
- Once that deploy-job has completed successfully, log into https://oss.sonatype.org/#stagingRepositories and close the Platform, JDT and PDE repositories.
116-
- If you do not have an account on oss.sonatype.org for performing the rest of the release request one by creating an issue like https://issues.sonatype.org/browse/OSSRH-43870 to get permissions for platform, JDT and PDE projects and tag an existing release engineer to give approval.
115+
- Once that deploy-job has completed successfully, log into https://central.sonatype.com/ and close the `Platform`, `JDT` and `PDE` repositories.
116+
- If you do not have an account on `central.sonatype.com` for performing the rest of the release request one by creating an [EF Help Desk](https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues) issue to get permissions for platform, JDT and PDE projects and tag an existing release engineer to give approval.
117117
* **Contribute to SimRel**
118118
- If SimRel is not updated before the I-builds are cleaned up (specifically the build for RC2/GA) it will break.
119119

0 commit comments

Comments
 (0)