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
Copy file name to clipboardExpand all lines: docs/spfx/toolchain/implement-ci-cd-with-azure-devops.md
+53-5Lines changed: 53 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,22 @@
1
1
---
2
2
title: Implement Continuous Integration and Continuous deployment using Azure DevOps
3
3
description: Streamlining the build and deployment process by automating manual steps.
4
-
ms.date: 09/06/2018
4
+
ms.date: 11/02/2018
5
5
ms.prod: sharepoint
6
6
---
7
7
8
-
9
8
# Implement Continuous Integration and Continuous deployment using Azure DevOps
9
+
10
10
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.
11
11
12
12
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.
13
13
14
14
## Continuous Integration
15
+
15
16
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.
16
17
17
18
Setting up Azure DevOps for Continuous Integration with a SharePoint Framework solution requires the following steps:
19
+
18
20
1. Creating the Build Definition
19
21
2. Installing NodeJS
20
22
3. Restoring dependencies
@@ -32,29 +34,37 @@ The Build Definition, as its name suggests, includes all the definitions and the
32
34
> 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.
33
35
34
36
### Installing NodeJS version 8
37
+
35
38
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.
> Make sure you specify `8.x` in the `Version Spec` field.
40
43
41
44
### Restoring dependencies
45
+
42
46
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`.
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
+
47
53

54
+
48
55
> [!NOTE]
49
56
> 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.
50
57
51
58
#### Configuring KarmaJS
59
+
52
60
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.
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
+
58
68
```JS
59
69
"use strict";
60
70
var existingKarmaConfig =require('@microsoft/sp-build-web/lib/karma/karma.config');
@@ -90,38 +100,51 @@ module.exports = function (config) {
90
100
```
91
101
92
102
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
+
93
104
```JS
94
105
const_=require('lodash');
95
106
var buildConfig =build.getConfig();
96
107
var karmaTask =_.find(buildConfig.uniqueTasks, (t) =>t.name==='karma');
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`.
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`.
105
120

106
121
107
122
### Packaging the solution
123
+
108
124
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
+
109
126

110
127
111
128
### Preparing the artifacts
129
+
112
130
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.
113
131
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
+
114
133

115
134
116
135
### 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`.
118
139

119
140
120
141
121
142
## Continuous Deployment
143
+
122
144
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.
123
145
124
146
Setting up Azure DevOps for Continuous Deployments with a SharePoint Framework solution requires the following steps:
147
+
125
148
1. Creating the Release Definition
126
149
2. Linking the Build Artifact
127
150
3. Creating the Environment
@@ -133,28 +156,40 @@ Setting up Azure DevOps for Continuous Deployments with a SharePoint Framework s
133
156
9. Setting the Variables for the Environment
134
157
135
158
### Creating the Release Definition
159
+
136
160
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
+
137
162
- Environment
138
163
- Deployment tasks
139
164
- Build artifacts
165
+
140
166

141
167
142
168
### Linking the Build Artifact
169
+
143
170
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
+
144
172

145
173
146
174
### Creating the Environment
175
+
147
176
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
+
148
178

149
179
150
180
### Installing NodeJS
181
+
151
182
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.
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.
> Learn more about the [Office 365 CLI](https://pnp.github.io/office365-cli/)
160
195
@@ -164,20 +199,25 @@ Before using the App Catalog in you deployment environment, you first need to au
164
199

165
200
166
201
### Adding the Solution Package to the App Catalog
202
+
167
203
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
+
168
205
> [!NOTE]
169
206
> 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.
170
207
171
208

172
209
173
210
### Deploying the Application
211
+
174
212
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
+
175
214
> [!NOTE]
176
215
> Make sure you update the package name.
177
216
178
217

179
218
180
219
### Setting the Variables for the Environment
220
+
181
221
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.
182
222
Add the following variables
183
223
| Name | Value |
@@ -186,22 +226,30 @@ Add the following variables
186
226
| password | Password of the user with administrative permissions on the tenant, do not forget to check the lockpad to mask it to other users |
187
227
| username | Username of the user with administrative permissions on the tenant |
188
228
| tenant | Tenant name in https://tenant.sharepoint.com eg `tenant`|
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
+
196
239

240
+
197
241
After a couple of minutes, your build should complete and show a result page like this one.
242
+
198
243

244
+
199
245
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
+
200
247

201
248
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.
0 commit comments