Warm tip: This article is reproduced from serverfault.com, please click

Nexus repository path

发布于 2020-12-14 18:05:07

I have uploaded some release artifacts from Jenkins to Nexus. I can see they have been created under Nexus as per the -Dversion I have provided.

Example: AppName-BuildNumber-Snapshot.zip

However, somehow the repository path is autogenerated, it has extra yyyymmdd.hhmmss appended to it.

Example: AppName-BuildNumber-Snapshot-yyyymmdd.hhmmss.zip

I would like to download the release artifact from Jenkins but due to the autogenerated Nexus repository path I am not able to download it in the separate job.

How can I force it to stop adding yyyymmdd.hhmmss to the repository path? Or is there anyway I can retrieve the repository path using AppName and BuildNumber?

Questioner
developer
Viewed
0
Ian W 2020-12-29 19:23:48

If you are uploading a SNAPSHOT, then Nexus dynamically stores it with a timestamp. That's because you can replace -SNAPSHOTs with newer copy w/same GAV. This is unlike real # jars which cannot/should not be redeployed, thus preserving their integrity.

To download a -SNAPSHOT, you just reference it as -SNAPSHOT; maven, aether, etc will retrieve the latest.

Maven (by default) only checks the remote repository for versions newer than your local once daily, unless you use -U option or change the updatePolicy.

If you want "solid" number, then you must release jar.

btw, you should see it's -yyyymmdd.hhmmss-nn, where nn is an incremental number for that version.


Nexus supports many different repository formats. If you only require maven, use Nexus 2 as it better supports maven. Repository types: Maven has two distinct types:Release and Snapshot Repositories.

If you want to "upload a zip file containing release artifacts and retrieve it back based on the build version number?", then that's what you should do.

You must configure a repository of type release, not snapshots (gleened from: -DrepositoryId=dsnexus-snapshots) (or in addition to type snapshots). To pass the "build version number", then presumably, you have:

[ X ] Create a formatted version number
Environment Variable Name [ label ]

Make sure your maven step has:

[ X ] Inject build variables

Then, mvn deploy:deploy-file -DgroupId=com.my.gid -DartifactId=AppName -Dversion=${label} -DrepositoryId=dsnexus-release

ps: you'll also want to implement a cleanup strategy in your Nexus repository if you are pumping every build as a new artifact.