Azure Artifacts is a package management solution provided by Microsoft Azure. It enables you to create, host, and share packages within your organization. These packages can include libraries, frameworks, modules, or any other components required by your software projects.
To start using Azure Artifacts and gain hands-on experience, follow these steps:
- Create an Azure Artifacts feed
Start by creating an Azure Artifacts feed in your Azure DevOps organization or Azure DevOps project. This feed will serve as a repository for your Maven packages.
- Generate Maven package credentials
To authenticate with your Azure Artifacts feed, you need to generate a Personal Access Token (PAT) in Azure DevOps. Follow these steps to generate the token:
- Go to your Azure DevOps organization or project.
- Click on your profile picture in the top-right corner and select "Personal access tokens".
- Click on "New Token" and provide a name for the token.
- Under "Scopes", select the appropriate permissions for your Maven packages (e.g., "Packaging (read, write, manage)").
- Click on "Create" and make sure to copy the generated token value. You will need this later.
- Configure Maven settings.xml
In your Maven project, you need to configure the settings.xml
file with the necessary Azure Artifacts feed information and credentials. Here's an example of how to configure it:
-
Open the
settings.xml
file located in your Maven installation'sconf
directory or in your user's.m2
directory. -
Add a
<servers>
section if it doesn't exist already:<servers> <server> <id>azure-artifacts</id> <username>USERNAME</username> <password>PAT</password> </server> </servers>
Replace
USERNAME
with any value (it doesn't matter), and replacePAT
with the Personal Access Token you generated in the previous step. -
Add a
<repositories>
section if it doesn't exist already:<repositories> <repository> <id>azure-artifacts</id> <url>https://pkgs.dev.azure.com/ORGANIZATION/_packaging/FEEDNAME/maven/v1</url> </repository> </repositories>
Replace
ORGANIZATION
with your Azure DevOps organization name, andFEEDNAME
with the name of your Azure Artifacts feed.
- Publish and consume Maven packages
With the configuration in place, you can now publish and consume Maven packages from your Azure Artifacts feed.
-
To publish a package, build your Maven project and execute the
mvn deploy
command. This will upload your package to the Azure Artifacts feed. -
To consume a package, simply include the appropriate dependency in your
pom.xml
file. For example:<dependencies> <dependency> <groupId>com.example</groupId> <artifactId>my-package</artifactId> <version>1.0.0</version> </dependency> </dependencies>
Replace
com.example
,my-package
, and1.0.0
with the actual coordinates of the package you want to consume.
That's it! You have now configured Azure Artifacts to work with Maven packages. Make sure to replace the placeholder values with your actual Azure DevOps organization, feed name, and credentials.
- Sign in to the Azure portal using your Azure account.
- Open the Azure Artifacts service.
- Click on "New feed" to create a new feed.
- Provide a name for your feed, select the appropriate organization, and choose a project to associate with the feed.
- Configure other settings such as visibility, upstream sources, etc., based on your requirements.
- Click on "Create" to create the feed.
- After creating the feed, navigate to its settings page.
- Click on "Connect to feed" to obtain the package source URL and authentication details.
- Make a note of the URL as you will need it for configuring your project to use the feed.
- Choose the package manager that aligns with your project's technology stack (e.g., npm, NuGet, Maven).
- For npm, use the following command to publish packages to your Azure Artifacts feed:
Replace
npm publish --registry=<feed-url> --scope=@<organization-scope>
<feed-url>
with the package source URL obtained in the previous step and<organization-scope>
with the appropriate scope for your organization.
To consume packages from your Azure Artifacts feed, configure your project to use the feed as a package source. The configuration steps vary depending on the package manager:
-
npm: Create or update a
.npmrc
file in your project's root directory and add the following line:registry=<feed-url>
Replace
<feed-url>
with the package source URL. -
NuGet: Add a NuGet configuration file (
NuGet.config
) to your project and specify the package source as follows:<configuration> <packageSources> <add key="<source-name>" value="<feed-url>" /> </packageSources> </configuration>
Replace
<source-name>
with a name for the package source and<feed-url>
with the package source URL. -
Maven: Add the package source to your project's
settings.xml
file, typically located in your.m2
directory. Add the following section:<settings> <profiles> <profile> <repositories> <repository> <id><source-name></id> <url><feed-url></url> </repository> </repositories> </profile> </profiles> </settings>
Replace
<source-name>
with a name for the package source and<feed-url>
with the package source URL.
Once your project is configured to use Azure Artifacts as a package source, you can install and use packages from the feed. Refer to the documentation of your specific package manager for instructions on installation and usage.
Please note that these steps provide a general overview of working with Azure Artifacts and package management. The process may vary depending on your project's requirements and the package manager you are using. For more detailed instructions, consult the official documentation and guides specific to your chosen package manager and Azure Artifacts.