title | description | ms.assetid | ms.reviewer | ms.topic | ms.custom | ms.date | monikerRange | zone_pivot_groups |
---|---|---|---|---|---|---|---|---|
Quickstart - Use Azure Pipelines to build and publish a Node.js package |
Build, deploy, and test JavaScript and Node.js apps with Azure Pipelines |
5BB4D9FA-DCCF-4661-B52B-0C42006A2AE5 |
vijayma |
quickstart |
seodec18, seo-javascript-september2019, contperf-fy20q4, devx-track-js, freshness-fy22q2, contperf-fy22q2 |
04/17/2023 |
<= azure-devops |
pipelines-version |
[!INCLUDE version-lt-eq-azure-devops]
You can use an Azure DevOps pipeline to build, deploy, and test JavaScript apps.
This quickstart walks through how to use a pipeline to create a Node.js package with Node Package Manager (npm) and publish a pipeline artifact.
::: moniker range=">=azure-devops-2020"
You must have the following items in Azure DevOps:
- A GitHub account where you can create a repository. Create one for free.
- An Azure DevOps organization and project. Create one for free.
- An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier.
::: moniker-end
::: zone pivot="pipelines-yaml"
::: moniker range="tfs-2018"
YAML is not available for TFS 2018.
::: moniker-end
::: moniker range=">=azure-devops-2020"
Fork the following sample Express.js server app at GitHub.
https://github.com/Azure-Samples/js-e2e-express-server
-
Sign in to Azure Pipelines. Your browser will go to
https://dev.azure.com/my-organization-name
and display your Azure DevOps dashboard. -
Go to your project and select Pipelines > Create a new pipeline.
-
Select GitHub as the location of your source code.
-
If you're redirected to GitHub to sign in, enter your GitHub credentials.
-
When the list of repositories appears, select your Node.js sample repository.
-
Azure Pipelines analyzes the code in your repository and recommends the
Node.js
template for your pipeline. Select that template. -
Azure Pipelines generates a YAML file for your pipeline. Select Save and run > Commit directly to the main branch, and then choose Save and run again.
-
A new run starts. Wait for the run to finish.
When you're done, you have a working YAML file azure-pipelines.yml in your repository that's ready for you to customize.
::: moniker-end
::: moniker range="azure-devops-2019"
-
Create a pipeline and select the YAML template.
-
Set the Agent pool and YAML file path for your pipeline.
-
Save the pipeline and queue a build. When the Build #nnnnnnnn.n has been queued message appears, select the number link to see your pipeline in action.
::: moniker-end
::: moniker range=">=azure-devops-2020"
-
Edit your azure-pipelines.yml file.
-
Update the Node.js Tool Installer task to use Node.js version 16 LTS.
trigger: - main pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '16.x' displayName: 'Install Node.js' - script: | npm install displayName: 'npm install' - script: | npm run build displayName: 'npm build'
-
Add new tasks to your pipeline to copy your npm package, package.json, and to publish your artifact. The Copy Files task copies files from local path on the agent where your source code files are downloaded and saves files to a local path on the agent where any artifacts are copied to before being pushed to their destination. Only the
src
andpublic
folders get copies. The Publish Pipeline Artifact task downloads the files from the earlier Copy Files tasks and makes them available as pipeline artifacts that will be published with your pipeline build.- task: CopyFiles@2 inputs: sourceFolder: '$(Build.SourcesDirectory)' contents: | src/* public/* targetFolder: '$(Build.ArtifactStagingDirectory)' displayName: 'Copy project files' - task: PublishPipelineArtifact@1 inputs: artifactName: e2e-server targetPath: '$(Build.ArtifactStagingDirectory)' publishLocation: 'pipeline' displayName: 'Publish npm artifact'
Save and run your pipeline. After your pipeline runs, verify that the job ran successfully and that you see a published artifact.
:::image type="content" source="media/node-artifact-run.png" alt-text="Screenshot of successful pipeline run with an artifact. ":::
::: moniker-end
::: zone-end
::: zone pivot="pipelines-classic"
-
Fork the following repo at GitHub.
https://github.com/Azure-Samples/js-e2e-express-server
-
After you have the sample code in your own repository, create your first pipeline and select the Empty process template.
-
Select Process under the Tasks tab in the pipeline editor and change the properties as follows:
- Agent queue:
Hosted Ubuntu Latest
- Agent queue:
-
Add the following tasks to the pipeline in the specified order:
-
npm
- Command:
install
- Command:
-
npm
- Display name:
npm test
- Command:
custom
- Command and arguments:
test
- Display name:
-
Publish Test Results
- Leave all the default values for properties
-
Archive Files
- Root folder or file to archive:
$(System.DefaultWorkingDirectory)
- Prepend root folder name to archive paths: Unchecked
- Root folder or file to archive:
-
Publish Build Artifacts
- Leave all the default values for properties
-
-
Save the pipeline and queue a build to see it in action.
::: zone-end
Congratulations, you've successfully completed this quickstart!
[!div class="nextstepaction"] Configure JavaScript