Skip to content

Commit eb88a19

Browse files
committed
DevOps article to TOC and small adjustments
1 parent c85d09f commit eb88a19

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

docs/spfx/toolchain/implement-ci-cd-with-azure-devops.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
22
title: Implement Continuous Integration and Continuous deployment using Azure DevOps
33
description: Streamlining the build and deployment process by automating manual steps.
4-
ms.date: 09/06/2018
4+
ms.date: 11/02/2018
55
ms.prod: sharepoint
66
---
77

8-
98
# Implement Continuous Integration and Continuous deployment using Azure DevOps
9+
1010
Azure DevOps (Visual Studio Team Services / Team Foundation Server) consists of a set of tools and services that help developers implement DevOps, Continuous Integration, and Continuous Deployment processes for their development projects.
1111

1212
This article explains the steps involved in setting up your Azure DevOps environment with with Continuous Integration and Continuous Deployment to automate your SharePoint Framework builds, unit tests, and deployment.
1313

1414
## Continuous Integration
15+
1516
Continuous Integration (CI) helps developers integrate code into a shared repository by automatically verifying the build using unit tests and packaging the solution each time new code changes are submitted.
1617

1718
Setting up Azure DevOps for Continuous Integration with a SharePoint Framework solution requires the following steps:
19+
1820
1. Creating the Build Definition
1921
2. Installing NodeJS
2022
3. Restoring dependencies
@@ -32,29 +34,37 @@ The Build Definition, as its name suggests, includes all the definitions and the
3234
> Build definitions can be described as a process template. It is a set of configured tasks that will be executed one after another on the source code every time a build is triggered. Tasks can be grouped in phases, by default a build definition contains at least one phase. You can add new tasks to the phase by clicking on the big plus sign next to the phase name.
3335
3436
### Installing NodeJS version 8
37+
3538
Once the Build Definition has been created, the first thing you need to do is instal NodeJS. Make sure to install version 8, as SharePoint Framework depends on it.
3639
![installing node 8](../../images/azure-devops-spfx-02.png)
3740

3841
> [!NOTE]
3942
> Make sure you specify `8.x` in the `Version Spec` field.
4043
4144
### Restoring dependencies
45+
4246
Because third party dependencies are not stored in the source control, you need to restore those before starting to build the project. To do so add a `npm` task and set the command to `install`.
4347
![installing dependencies](../../images/azure-devops-spfx-03.png)
4448

4549
### Executing Unit Tests
50+
4651
The SharePoint Framework supports writing units tests using KarmaJS, Mocha, Chai and Sinon. These modules are already referenced for you and it is highly recommended at a minimum to test the business logic of your code to get feedback on any potential issues or regressions as soon as possible. To have Azure DevOps execute your unit tests, add a `gulp` task. Set the path to the `gulpfile` file and set the `Gulp Tasks` option to `test`.
52+
4753
![executing unit tests](../../images/azure-devops-spfx-04.png)
54+
4855
> [!NOTE]
4956
> Make sure you check `Publish to TFS/Team Services` under the `JUnit Test Results` section and set the `Test Result Files` to `**/test-*.xml`. This will instruct the task to report results with the build status in Azure DevOps.
5057
5158
#### Configuring KarmaJS
59+
5260
By default SharePoint Framework projects do not include a reporter for JUnit. Reporters are plugins for KarmaJS that export the test results in a certain format. To install the necessary reporters, run the following commands in your project.
5361

5462
```shell
5563
5664
```
65+
5766
You also need to configure KarmaJS to load an use the reporter, to do so create a file `config/karma.config.js` and add the following content.
67+
5868
```JS
5969
"use strict";
6070
var existingKarmaConfig = require('@microsoft/sp-build-web/lib/karma/karma.config');
@@ -90,38 +100,51 @@ module.exports = function (config) {
90100
```
91101

92102
Finally you need to modify the gulpfile to instruct it to leverage this new configuration. To do so edit `gulpfile.js` and add these lines after `build.initialize(gulp);`.
103+
93104
```JS
94105
const _ = require('lodash');
95106
var buildConfig = build.getConfig();
96107
var karmaTask = _.find(buildConfig.uniqueTasks, (t) => t.name === 'karma');
97108
karmaTask.taskConfig.configPath = './config/karma.config.js';
98109
```
110+
99111
### Importing code coverage information
112+
100113
In order to get code coverage reported with the build status you need to add a task to import that information. To configure the code coverage information, add the `publish code coverage results` tasks. Make sure you set the tool to `Cobertura`, `Summary files` to `$(Build.SourcesDirectory)/temp/coverage/cobertura/cobertura.xml` and `Report Directory` to `$(Build.SourcesDirectory)/temp/coverage/cobertura`.
114+
101115
![importing coverage information](../../images/azure-devops-spfx-05.png)
102116

103117
### Bundling the solution
118+
104119
You first need to bundle your solution in order to get static assets that can be understood by a web browser. Add another `gulp` task, set the `gulpfile` path, set the `Gulp Tasks` field to bundle and add `--ship` in the `Arguments`.
105120
![bundling the assets](../../images/azure-devops-spfx-06.png)
106121

107122
### Packaging the solution
123+
108124
Now that you have static assets, the next step is to combine the assets into a package SharePoint will be able to deploy. Add another `gulp` task, set the `gulpfile` path, set the `Gulp Tasks` field to `package-solution` and add `--ship` in the `Arguments`.
125+
109126
![packaging the solution](../../images/azure-devops-spfx-07.png)
110127

111128
### Preparing the artifacts
129+
112130
By default, an Azure DevOps build does not retain any files. To ensure that the required files needed for the release are retained, you need to explicitly indicate which files should be kept.
113131
Add a `Copy Files` task and set the `Contents` to `**\*.sppkg` (the SharePoint Package created with the previous task) and the target folder to `$(build.artifactstagingdirectory)/drop`.
132+
114133
![grabbing the artifacts](../../images/azure-devops-spfx-08.png)
115134

116135
### Publishing the artifacts
117-
Now that you have collected all the files needed for deployment in a special artifacts folder, you still need to instruct Azure DevOps to keep these files after the execution of the build. To do so add a `Publish artifacts` task and set the `Path to publish` to `$(build.artifactstagingdirectory)/drop` and the `Artifact name` to `drop`.
136+
137+
Now that you have collected all the files needed for deployment in a special artifacts folder, you still need to instruct Azure DevOps to keep these files after the execution of the build. To do so add a `Publis
138+
h artifacts` task and set the `Path to publish` to `$(build.artifactstagingdirectory)/drop` and the `Artifact name` to `drop`.
118139
![publishing the artifacts](../../images/azure-devops-spfx-09.png)
119140

120141

121142
## Continuous Deployment
143+
122144
Continuous Deployment (CD) takes validated code packages from build process and deploys them into a staging or production environment. Developers are able to track which deployments were successful or not and narrow down the issues to the particular package versions.
123145

124146
Setting up Azure DevOps for Continuous Deployments with a SharePoint Framework solution requires the following steps:
147+
125148
1. Creating the Release Definition
126149
2. Linking the Build Artifact
127150
3. Creating the Environment
@@ -133,28 +156,40 @@ Setting up Azure DevOps for Continuous Deployments with a SharePoint Framework s
133156
9. Setting the Variables for the Environment
134157

135158
### Creating the Release Definition
159+
136160
Start by creating a new Release Definition with an empty template. A Release Defition is a process that is used to identify the following elements for the deployment:
161+
137162
- Environment
138163
- Deployment tasks
139164
- Build artifacts
165+
140166
![creating the release definition](../../images/azure-devops-spfx-10.png)
141167

142168
### Linking the Build Artifact
169+
143170
Click on `Add an artifact` and select the build definition you previously created. Write down the `Source Alias` name you set, as you will need to use it in subsequent tasks.
171+
144172
![linking the artifacts](../../images/azure-devops-spfx-11.png)
145173

146174
### Creating the Environment
175+
147176
When you create your continuous deployment environment, you can give a name and configure pre-deployment approvals, artificats filters (i.e. deploy only if the build comes from this or that branch), and much more by clicking on the buttons around the environment box or directly on the title.
177+
148178
![creating the environment](../../images/azure-devops-spfx-12.png)
149179

150180
### Installing NodeJS
181+
151182
By click on `1 job, 0 tasks` you can access the tasks configuration view, which works similarly to the build definition. Here, you can select the set of tasks that will run only for this specific environment. This includes installing NodeJS version 8 or later.
152-
Add a `Node tool installer` task and define `8.X` in the `Version Spec` field.
183+
Add a `Node tool installer` task and define `8.X` in the `Version Spec` field.
184+
153185
![installing node 8](../../images/azure-devops-spfx-13.png)
154186

155187
### Installing the Office 365 CLI
188+
156189
The Office 365 Common Language Interface (CLI) is an open source project built by the OfficeDev PnP Community. In order to leverage the CLI as part of your Release Definition, you first need to install it. Then, you will be able to take advantage of commands available to handle deployment. Add a `npm` task, select a `Custom` command and type `install -g @pnp/office365-cli` in the `Command and Arguments` field.
190+
157191
![installing office 365 cli](../../images/azure-devops-spfx-14.png)
192+
158193
> [!NOTE]
159194
> Learn more about the [Office 365 CLI](https://pnp.github.io/office365-cli/)
160195
@@ -164,20 +199,25 @@ Before using the App Catalog in you deployment environment, you first need to au
164199
![connecting to the app catalog](../../images/azure-devops-spfx-15.png)
165200

166201
### Adding the Solution Package to the App Catalog
202+
167203
Upload the solution package to your App Catalog by adding another `Command Line` task and pasting the following command line in the `Script` field `o365 spo app add -p $(System.DefaultWorkingDirectory)/SpFxDevOps/drop/SharePoint/solution/sp-fx-devops.sppkg --overwrite`
204+
168205
> [!NOTE]
169206
> The path of the package depends on your solution name (see your project configuration) as well as the `Source Alias` you defined earlier, make sure they match.
170207
171208
![uploading the package to the catalog](../../images/azure-devops-spfx-16.png)
172209

173210
### Deploying the Application
211+
174212
The final step in the setup is to deploy the application to the App Catalog to make it available to all site collections within the tenant as it's latest version. Add another `Command Line` taks and paste the follwing command line in the `Script` field `o365 spo app deploy --name sp-fx-devops.sppkg --appCatalogUrl https://$(tenant).sharepoint.com/$(catalogsite)`
213+
175214
> [!NOTE]
176215
> Make sure you update the package name.
177216
178217
![Deploying the package to the catalog](../../images/azure-devops-spfx-17.png)
179218

180219
### Setting the Variables for the Environment
220+
181221
The tasks you configured in the last step rely on Azure DevOps process variables (easily identified with the `$(variableName)` syntax). You need to define those variables before being able to run the build definition. To do so, click on the `Variables` tab.
182222
Add the following variables
183223
| Name | Value |
@@ -186,22 +226,30 @@ Add the following variables
186226
| password | Password of the user with administrative permissions on the tenant, do not forget to check the lockpad to mask it to other users |
187227
| username | Username of the user with administrative permissions on the tenant |
188228
| tenant | Tenant name in https://tenant.sharepoint.com eg `tenant` |
229+
189230
![Variables setup](../../images/azure-devops-spfx-18.png)
190231

191232
> [!NOTE]
192233
> Make sure you save your release definition.
193234
194235
## Testing
236+
195237
To test your newly created Continuous Deployment process, return to the `Builds` section in Azure DevOps, select your build definition and click on `Queue`. Select your branch, and click on `Queue`. A new build will be created and will start building.
238+
196239
![Queuing a build](../../images/azure-devops-spfx-19.png)
240+
197241
After a couple of minutes, your build should complete and show a result page like this one.
242+
198243
![Results of a build](../../images/azure-devops-spfx-20.png)
244+
199245
If you navigate to the `Release` section of Azure DevOps, a new release should have started automatically. After a few minutes your release should complete and your SharePoint Framework solution is deployed to your tenant.
246+
200247
![Results of a release](../../images/azure-devops-spfx-21.png)
201248

202-
Your DevOps pipeline for your SharePoint Framework solution in Azure DevOps is now set up and ready to be customized further to your scenario.
249+
Your DevOps pipeline for your SharePoint Framework solution in Azure DevOps is now set up and ready to be customized further to your scenario.
203250

204251
## See Also
252+
205253
- [SharePoint Framework Overview](../sharepoint-framework-overview.md)
206254
- [Sample Project on GitHub](https://github.com/SharePoint/sp-dev-build-extensions/tree/master/samples/azure-devops-ci-cd-spfx)
207255
- [Integrate Gulp Tasks in the build pipeline](./integrate-gulp-tasks-in-build-pipeline.md)

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@
230230
href: spfx/toolchain/sharepoint-framework-toolchain.md
231231
- name: Yeoman generator
232232
href: spfx/toolchain/scaffolding-projects-using-yeoman-sharepoint-generator.md
233+
- name: CI and CD
234+
href: spfx/toolchain/implement-ci-cd-with-azure-devops.md
233235
- name: Debugging
234236
href: spfx/debug-in-vscode.md
235237
items:

0 commit comments

Comments
 (0)