You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
17
17
18
18
## Prerequisites
19
19
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.
21
21
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.
23
23
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).
25
25
26
-
## Publish to Azure Artifacts feeds
26
+
## Publish packages to a feed in the same organization
27
27
28
28
> [!NOTE]
29
29
> 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.
30
30
31
31
#### [YAML](#tab/yaml/)
32
32
33
33
```yaml
34
-
- task: Npm@1
34
+
steps:
35
+
- task: NodeTool@0
35
36
inputs:
36
-
command: publish
37
-
publishRegistry: useFeed
38
-
publishFeed: <FEED_NAME> ## For project-scoped feeds, use: <PROJECT_NAME>/<FEED_NAME>
39
-
```
37
+
checkLatest: true
40
38
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
43
43
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
+
```
46
48
47
49
#### [Classic](#tab/classic/)
48
50
49
-
::: moniker range="azure-devops-2019"
51
+
::: moniker range="azure-devops"
50
52
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.
52
54
53
-
2. Select **Pipelines** > **Builds**, and then select your build definition.
55
+
::: moniker-end
54
56
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"
56
58
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.
58
60
59
61
::: moniker-end
60
62
61
-
::: moniker range="> azure-devops-2019"
63
+
::: moniker range="azure-devops-2019"
62
64
63
-
1. Navigate to the Azure DevOps portal, and then select your project.
65
+
2. Select **Pipelines** > **Builds**, and then select your build definition.
64
66
65
-
2. Select **Pipelines**, and then select your pipeline definition.
67
+
::: moniker-end
66
68
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"
68
70
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.
70
72
71
73
::: moniker-end
72
74
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:
74
76
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.
78
78
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
+
```
80
85
81
86
* * *
82
87
83
-
## Publish to a public registry
88
+
## Publish packages to a feed in another organization
84
89
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.
86
91
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.
88
93
89
-
1. Select **Project settings** > **Service connections**, and then select **Create service connection**.
94
+
#### Create a service connection
90
95
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.
92
97
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.
1. Sign in to your Azure DevOps organization, and then navigate to your project.
104
111
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.
107
113
108
-
#### [Classic](#tab/classic/)
114
+
1. Select **Edit**, and then add the following snippet to your YAML pipeline.
109
115
110
-
::: moniker range="azure-devops-2019"
116
+
```yaml
117
+
- task: NodeTool@0
118
+
inputs:
119
+
checkLatest: true
111
120
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
+
```
113
131
114
-
2. Select **Pipelines** > **Builds**, and then select your build definition.
132
+
#### [Classic](#tab/classic/)
115
133
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"
117
135
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.
119
137
120
138
::: moniker-end
121
139
122
-
::: moniker range="> azure-devops-2019"
140
+
::: moniker range="< azure-devops"
123
141
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.
125
143
126
-
2. Select **Pipelines**, and then select your pipeline definition.
144
+
::: moniker-end
127
145
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"
129
147
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.
131
149
132
150
::: moniker-end
133
151
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"
135
153
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.
139
155
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
141
157
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
+
***
143
172
144
-
## Related articles
173
+
## Related content
145
174
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)
0 commit comments