Skip to content

Commit 84c7aa6

Browse files
authored
Merge pull request MicrosoftDocs#7411 from MicrosoftDocs/pipelines/334964
npm lightweight task & overhaul
2 parents b25cf75 + 3f4f995 commit 84c7aa6

File tree

2 files changed

+97
-68
lines changed

2 files changed

+97
-68
lines changed

docs/artifacts/tutorials/share-packages-publicly.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Public feeds are project-scoped feeds in a public project. Public feeds inherit
7676

7777
#### [Npm](#tab/npm)
7878

79-
- [Publish Npm packages](../../pipelines/artifacts/npm.md#publish-to-azure-artifacts-feeds)
79+
- [Publish Npm packages](../../pipelines/artifacts/npm.md#publish-packages-to-a-feed-in-the-same-organization)
8080

8181
#### [Maven](#tab/maven)
8282

docs/pipelines/artifacts/npm.md

+96-67
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Publish npm packages with Azure Pipelines
33
ms.custom: devx-track-js
4-
description: Learn how to publish npm packages to your feed using Azure Pipelines.
4+
description: Learn how to publish npm packages to internal and external feed using Azure Pipelines.
55
ms.assetid: F4C61B91-2C5B-4848-A4BF-B658F549673A
66
ms.topic: conceptual
7-
ms.date: 05/30/2024
7+
ms.date: 11/14/2024
88
monikerRange: '<= azure-devops'
99
"recommendations": "true"
1010
---
@@ -13,136 +13,165 @@ monikerRange: '<= azure-devops'
1313

1414
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
1515

16-
With Azure Pipelines, you can publish your npm packages to Azure Artifacts feeds and public registries like npmjs.com. This article will guide you through publishing your npm packages using both YAML and Classic pipelines.
16+
With Azure Pipelines, you can publish your npm packages to Azure Artifacts feeds within your organization and in other organizations. This article will guide you through publishing your npm packages to internal and external feeds using YAML and Classic pipelines.
1717

1818
## Prerequisites
1919

20-
- An Azure DevOps organization. [Create one for free](../../organizations/accounts/create-organization.md).
20+
- Create an Azure DevOps [organization](../../organizations/accounts/create-organization.md) and a [project](../../organizations/projects/create-project.md#create-a-project) if you haven't already.
2121

22-
- An Azure DevOps project. Create a new [project](../../organizations/projects/create-project.md#create-a-project) if you don't have one already.
22+
- Create a [new feed](../../artifacts/get-started-nuget.md#create-feed) if you don't have one already.
2323

24-
- An Azure Artifacts feed. [Create one for free](../../artifacts/get-started-npm.md#create-a-feed).
24+
- If you're using a self-hosted agent, make sure that it has [Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
2525

26-
## Publish to Azure Artifacts feeds
26+
## Publish packages to a feed in the same organization
2727

2828
> [!NOTE]
2929
> To publish your packages to a feed using Azure Pipelines, ensure that both the **Project Collection Build Service** and your project's **Build Service** identity are configured as a **Feed Publisher (Contributor)**. See [Add new users/groups](../../artifacts/feeds/feed-permissions.md#feed-settings) for more details.
3030
3131
#### [YAML](#tab/yaml/)
3232

3333
```yaml
34-
- task: Npm@1
34+
steps:
35+
- task: NodeTool@0
3536
inputs:
36-
command: publish
37-
publishRegistry: useFeed
38-
publishFeed: <FEED_NAME> ## For project-scoped feeds, use: <PROJECT_NAME>/<FEED_NAME>
39-
```
37+
checkLatest: true
4038

41-
- **publishRegistry**: select *useFeed* to use a feed within your organization. Options: *useExternalRegistry*, *useFeed*
42-
- **publishFeed**: the feed you want to publish to. Required when publishRegistry = useFeed.
39+
- task: npmAuthenticate@0
40+
displayName: 'Authenticate to Azure Artifacts feed'
41+
inputs:
42+
workingFile: .npmrc
4343

44-
> [!TIP]
45-
> When adding the npm task to your YAML pipeline using the YAML editor, the project and feed IDs for your `publishFeed` will be generated automatically.
44+
- script: |
45+
npm publish
46+
displayName: Publish
47+
```
4648
4749
#### [Classic](#tab/classic/)
4850
49-
::: moniker range="azure-devops-2019"
51+
::: moniker range="azure-devops"
5052
51-
1. Sign in to your Azure DevOps collection, and then navigate to your project.
53+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
5254
53-
2. Select **Pipelines** > **Builds**, and then select your build definition.
55+
::: moniker-end
5456
55-
3. Select **Edit**, and then select the `+` sign to add a new task. Search for the *npm* task, and then select **Add** to add it to your pipeline.
57+
::: moniker range="< azure-devops"
5658
57-
:::image type="content" source="./media/add-npm-task.png" alt-text="A screenshot that shows how to find and add the npm task.":::
59+
1. Sign in to your Azure DevOps collection, and then navigate to your project.
5860
5961
::: moniker-end
6062
61-
::: moniker range="> azure-devops-2019"
63+
::: moniker range="azure-devops-2019"
6264
63-
1. Navigate to the Azure DevOps portal, and then select your project.
65+
2. Select **Pipelines** > **Builds**, and then select your build definition.
6466
65-
2. Select **Pipelines**, and then select your pipeline definition.
67+
::: moniker-end
6668
67-
3. Select **Edit**, and then select the `+` sign to add a new task. Search for the *npm* task, and then select **Add** to add it to your pipeline.
69+
::: moniker range="> azure-devops-2019"
6870
69-
:::image type="content" source="./media/add-npm-task.png" alt-text="A screenshot that shows how to find and add the npm task.":::
71+
2. Select **Pipelines**, and then select your pipeline definition.
7072
7173
::: moniker-end
7274
73-
4. Name your task and then select **Publish** from the commands dropdown menu. Specify your *package.json* path, your **Registry location**, and your **Target registry**.
75+
3. Select **Edit**, and then select the `+` sign to add a new task. Add the *Node.js tool installer*, *npm Authenticate* and *Command line* tasks to your pipeline definition. You can leave the *Node.js tool installer* task with the default settings and configure the *npm Authenticate* and *Command line* tasks as follows:
7476

75-
- **Working folder that contains package.json**: path to the folder containing the target *package.json* and *.npmrc* files. Leave this blank if those files are at the root of your repo.
76-
- **Registry location**: select **Registry I select here** to publish to a feed.
77-
- **Target registry**: select your feed from the dropdown menu.
77+
1. **npm Authenticate task**: Select the path to the *.npmrc* file.
7878

79-
:::image type="content" source="./media/npm-publish.png" alt-text="A screenshot that shows how to configure the npm task to publish packages to an Azure Artifacts feed.":::
79+
1. **Command line task**:
80+
- **Display name**: Publish.
81+
- **Script**:
82+
```
83+
npm publish
84+
```
8085

8186
* * *
8287

83-
## Publish to a public registry
88+
## Publish packages to a feed in another organization
8489

85-
Before publishing your packages to a public npm registry like npmjs.com, you must first create a service connection to authenticate with the desired external service.
90+
To publish your packages to a feed in another Azure DevOps organization, you must first create a personal access token in the target organization.
8691

87-
1. Sign in to your Azure DevOps organization, and then navigate to your project.
92+
Navigate to the organization hosting your target feed and [Create a personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) with **Packaging** > **Read & write** scope. Copy your personal access token as you'll need it in the following section.
8893

89-
1. Select **Project settings** > **Service connections**, and then select **Create service connection**.
94+
#### Create a service connection
9095

91-
:::image type="content" source="./media/create-service-connection.png" alt-text="A screenshot that shows how to create a new service connection in Azure DevOps.":::
96+
1. Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.
9297

93-
1. Select **npm** and then select **Next**. Fill out the required fields, and then select **Save** when you're done.
98+
1. Navigate to your **Project settings** > **Service connections**.
99+
100+
1. Select **New service connection**, select **npm**, and then select **Next**.
101+
102+
1. Select **Username and Password** as the **Authentication method**, and then enter your **Registry URL**. Enter your **Username** (a placeholder, as Azure Pipelines will use your `.npmrc` configuration file and the personal access token you created earlier to authenticate). For **Password**, paste your personal access token. Provide a name for your service connection, and check the **Grant access permission to all pipelines** checkbox.
103+
104+
1. Select **Save** when you're done.
105+
106+
#### Publish packages
94107

95108
#### [YAML](#tab/yaml/)
96109

97-
```yaml
98-
- task: Npm@1
99-
inputs:
100-
command: publish
101-
publishRegistry: useExternalRegistry
102-
publishEndpoint: '<NAME_OF_YOUR_SERVICE_CONNECTION>'
103-
```
110+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
104111

105-
- **publishRegistry**: select *useExternalRegistry* to publish to a public registry. Options: useExternalRegistry | useFeed.
106-
- **publishEndpoint**: replace the placeholder with the name of the service connection you created earlier. required when *publishRegistry* == *useExternalRegistry*.
112+
1. Select **Pipelines**, and then select your pipeline definition.
107113

108-
#### [Classic](#tab/classic/)
114+
1. Select **Edit**, and then add the following snippet to your YAML pipeline.
109115

110-
::: moniker range="azure-devops-2019"
116+
```yaml
117+
- task: NodeTool@0
118+
inputs:
119+
checkLatest: true
111120
112-
1. Sign in to your Azure DevOps collection, and then navigate to your project.
121+
- task: npmAuthenticate@0
122+
displayName: 'Authenticate to Azure Artifacts feed'
123+
inputs:
124+
workingFile: .npmrc
125+
customEndpoint: <SERVICE_CONNECTION_NAME>
126+
127+
- script: |
128+
npm publish
129+
displayName: Publish
130+
```
113131

114-
2. Select **Pipelines** > **Builds**, and then select your build definition.
132+
#### [Classic](#tab/classic/)
115133

116-
3. Select **Edit**, and then select the `+` sign to add a new task. Search for the *npm* task, and then select **Add** to add it to your pipeline.
134+
::: moniker range="azure-devops"
117135

118-
:::image type="content" source="./media/add-npm-task.png" alt-text="A screenshot that shows how to find and add the npm task.":::
136+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
119137

120138
::: moniker-end
121139

122-
::: moniker range="> azure-devops-2019"
140+
::: moniker range="< azure-devops"
123141

124-
1. Navigate to the Azure DevOps portal, and then select your project.
142+
1. Sign in to your Azure DevOps collection, and then navigate to your project.
125143

126-
2. Select **Pipelines**, and then select your pipeline definition.
144+
::: moniker-end
127145

128-
3. Select **Edit**, and then select the `+` sign to add a new task. Search for the *npm* task, and then select **Add** to add it to your pipeline.
146+
::: moniker range="azure-devops-2019"
129147

130-
:::image type="content" source="./media/add-npm-task.png" alt-text="A screenshot that shows how to find and add the npm task.":::
148+
2. Select **Pipelines** > **Builds**, and then select your build definition.
131149

132150
::: moniker-end
133151

134-
4. Name your task and then select **Publish** from the commands dropdown menu. Specify your *package.json* path, your **Registry location**, and your **External registry**.
152+
::: moniker range="> azure-devops-2019"
135153

136-
- **Working folder that contains package.json**: path to the folder containing the target *package.json* and *.npmrc* files. Leave this blank if those files are at the root of your repo.
137-
- **Registry location**: select **External npm registry** to publish to a public registry such as npmjs.com.
138-
- **External registry**: select the service connection you created earlier.
154+
2. Select **Pipelines**, and then select your pipeline definition.
139155

140-
:::image type="content" source="./media/npm-publish-registry.png" alt-text="A screenshot that shows how to configure the npm task to publish packages to a public registry.":::
156+
::: moniker-end
141157

142-
* * *
158+
3. Select **Edit**, and then select the `+` sign to add a new task. Add the *Node.js tool installer*, *npm Authenticate* and *Command line* tasks to your pipeline definition. You can leave the *Node.js tool installer* task with the default settings and configure the *npm Authenticate* and *Command line* tasks as follows:.
159+
160+
1. **npm Authenticate task**:
161+
1. Select the path to your *.npmrc* file.
162+
1. Select the service connection you created earlier from the **Credentials for registries outside this organization/collection** dropdown menu.
163+
164+
1. **Command line task**:
165+
- **Display name**: Publish.
166+
- **Script**:
167+
```
168+
npm publish
169+
```
170+
171+
***
143172

144-
## Related articles
173+
## Related content
145174

146-
- [Publish and restore npm packages from the command line](../../artifacts/npm/publish.md).
147-
- [Use packages from npmjs.com](../../artifacts/npm/upstream-sources.md).
148-
- [Publish and download pipeline artifacts](./pipeline-artifacts.md).
175+
- [Publish and download pipeline artifacts](../artifacts/build-artifacts.md)
176+
- [Use the .artifactignore file](../../artifacts/reference/artifactignore.md)
177+
- [Deploy pull request Artifacts](../release/deploy-pull-request-builds.md).

0 commit comments

Comments
 (0)