1

When I run my build pipeline, all the libraries will publish to the Azure DevOps Artifacts(Because they will downloaded in Maven Central).

But I have a external libraries which I have created manually on my local computer and it's a jar like this picture.external libraries jar

I want to add this jar to Azure DevOps Artifacts so that when next time I run my pipeline, it can access to my external libraries jar.

How can I do it? I have tried this solution. But it cannot work.

az artifacts universal publish --organization https://dev.azure.com/example/ --feed my_feed --name my-artifact-name --version 0.0.1 --description "Test Description" --path this solution

jasonroy7dct
  • 29
  • 2
  • 8

2 Answers2

1

Artifacts deployed with universal publish can't be read by maven projects, which makes them useless outside Azure Pipelines.

To deploy your libs or external jars to azure you should configure your settings.xml as per feed instructions, e.g.,

  <servers>
    <server>
      <id>FeedId</id>
      <username>user</username>
      <password>token</password>
    </server>
  </servers>

And then use a deploy-file goal

mvn org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file -Dpackaging=jar -DrepositoryId=FeedId -Durl=https://pkgs.dev.azure.com/<org>/_packaging/FeedId/maven/v1 -DgroupId=my.group.id -DartifactId=artifactId -Dversion=1.0 -Dfile=<path_to_local.jar> -DpomFile=<path_to_local.pom>

Make sure to use 2.4 version if the file already resides in your local repo (~/.m2/repository/my/group/id/artifactId). Since version 2.5+ the deploy plugin will fail to deploy jars already present in the local repo.

  • I tried using the az universal artifacts commands and uploaded a jar. As you say maven projects can't read the file(s) as they don't have any maven coordinates in the AZ artifacts feed. I tried this approach and it works as expected. The files need to be copied to some temp directory otherwise from your local .m2 you'll get the failure message "Cannot deploy artifact from the local repository". – David Victor Jun 28 '23 at 08:09
0

You can refer to the document about az artifacts universal publish. Here is my sample:

1.Log into Azure DevOps:

az login

or

az devops login --organization https://dev.azure.com/{Organization}/

2.Publish packages:

My file is in the C:\sample folder:

enter image description here

Here is my command:

az artifacts universal publish --organization https://dev.azure.com/{Organization}/ --feed {Feed name} --name sample.jar --version 0.0.1 --description "Welcome to Universal Packages" --path C:\sample\sample.jar.

enter image description here In addition, it is Organization scoped feeds.

enter image description here

If you are publishing packages to Project scoped feeds, please also add project name in your command:

az artifacts universal publish --organization https://dev.azure.com/{Organization}/ --project="{Project}" --scope project --feed {Feed name} --name my-first-package --version 0.0.1 --description "Welcome to Universal Packages" --path .
Walter
  • 2,640
  • 1
  • 5
  • 11
  • I tried it, but I still cannot access it. Because it seems like I just uploaded an empty .jar on to the Azure DevOps Artifacts – jasonroy7dct Jan 19 '21 at 06:28
  • and if I want to upload the .jar, it has an error: `The package name provided is invalid. Universal package names must be one or more lowercase alphanumeric segments separated by a dash, dot or underscore. The package name must be under 256 characters.` – jasonroy7dct Jan 19 '21 at 06:30
  • Please pay attention to your artifact name. For example, you cannot use logger-wrapper-api-1.0-SNAPSHOT.jar as the artifact name because it contains uppercase letters. Please share your complete command if you still have issues. – Walter Jan 19 '21 at 06:55
  • I successfully add the files to the Azure DevOps Artifacts, but how can I access this .jar when I want to run the build pipeline while the artifact name isn't **logger-wrapper-api-1.0-SNAPSHOT.jar** ?(I called my artifact name: loggerwrapper.jar) – jasonroy7dct Jan 19 '21 at 07:18
  • You can use Download package task in pipeline. If when you publish, the name of the local file is logger-wrapper-api-1.0-SNAPSHOT.jar, then the download package is also this name. – Walter Jan 19 '21 at 08:04
  • sorry, so do I have to modify the pom.xml? Otherwise I cannot access the artifacts package in Azure DevOps? ` com.ibm.logmanager.loggerwrapper logger-wrapper-api 1.0-SNAPSHOT ` – jasonroy7dct Jan 19 '21 at 08:18
  • I think you need to publish Maven packages instead of Universal packages. Please refer to [this document](https://learn.microsoft.com/en-us/azure/devops/artifacts/maven/install?view=azure-devops). – Walter Jan 19 '21 at 09:30
  • Have your tried the steps in the document above? Would you please share your latest information about this issue? If you have any concern, feel free to share it here. – Walter Jan 22 '21 at 09:30