Skip to content

Instantly share code, notes, and snippets.

@cstamas
Last active May 15, 2024 19:24
Show Gist options
  • Save cstamas/69e6365bbb70521923020d68369bf8e5 to your computer and use it in GitHub Desktop.
Save cstamas/69e6365bbb70521923020d68369bf8e5 to your computer and use it in GitHub Desktop.

How to deploy to same staging repository from different computers

You need a Nexus2 account (ASF, OSS or S01), and staging profile set up. This example will use Maveniverse as example, that is set up on s01.oss.sonatype.org instance.

All you need is to:

  • figure out profile ID
  • use that profile ID and "start" staging (it creates a transient "staging repository" for you)
  • figure out the repository URL
  • deploy to that repository from anywhere you want using plan m-deploy-p (or whatever)
  • close the repository, if all okay, release it

Step 1: figure out profile ID

Issue a REST request toward Nx2 to "evaluate" your deployment intent (mostly by groupID). Example:

curl -u $USERNAME \
  -H "Accept: application/json" \
  "https://s01.oss.sonatype.org/service/local/staging/profile_evaluate?t=maven2&g=eu.maveniverse.maven&a=whatever&v=whatever"

What matters: the g=$GROUP_ID should have your targeted (top level, if multi module) group ID of the project being staged.

Response will contain JSON, you need "id" that holds the Staging Profile ID.

Step 2: create staging repository using profile ID

Issue a REST request toward Nx2 to "start" staging, in other words, to crean an opened transient staging repository for you. Example:

curl -u $USERNAME \
  -H "Accept: application/json" \
  -H "Content-type: application/json" \
  -X POST -d '{"data": {"description": "whatever"}}' \
  "https://s01.oss.sonatype.org/service/local/staging/profiles/$PROFILE_ID/start"

What matters: The $PROFILE_ID should contain the Staging Profile ID you got in Step 1. Eventually, you can set description as well (instead of "whatever"), that will show up on the UI of the created staging repository.

Response will contain $REPOSITORY_ID created for you (field stagingRepositoryId).

Step 3: figure out the URL of the created repository.

It is constructed as this:

https://s01.oss.sonatype.org/service/local/staging/deployByRepositoryId/$REPOSITORY_ID/

Just use this URL as altDeploymentRepository on any machine you want.

Note: this URL unlike the "well known" https://s01.oss.sonatype.org/service/local/staging/deploy/maven2 one does NOT aut-create new staging repository! This latter one is to provide some "compatibility" with plain maven-deploy-plugin, as Nx2 will based on client IP, UserAgent and deploy GroupId figure out all these (Step1, step2, etc) automatically, and create on-the-fly new repository. In case of multi machine deploy, at least the IP address will differ, so this latter URL does not work for this use case.

Step 4: close it

Once done, go to the UI (in this case S01) and close the staging repository. Or, issue a REST call like this:

curl -u $USERNAME \
  -H "Accept: application/json" \
  -H "Content-type: application/json" \
  -X POST -d '{"data": {"description": "whatever"}}' \
  "https://s01.oss.sonatype.org/service/local/staging/profiles/$PROFILE_ID/finish"

And this will close it (if can, depends on rules).

Step 5 and beyond...

Grab a beer...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment