az-pipelines-2-sharepoint is an Azure DevOps extensions to upload file or build artefacts to a SharePoint Online library via Microsoft Graph.
This extension can not be used with on-premise SharePoint installations.
Azure Pipelines: Visit the Marketplace page and click install. Choose your Azure DevOps organization.
Azure DevOps Server: Visit the Marketplace page and click install. Then choose Download and install it via the Extension page on your local Azure DevOps Server.
Register a new application in your Azure AD tenant: (For more info, refer to the Microsoft Docs)
- Choose any name.
- Supported Account types: Accounts in this organizational directory only.
- No Redirect URL is needed.
- Add a client secret as authentication method.
- For testing or small environments, add the API permissions:
Microsoft Graph
->Application permissions
->Files
->Files.ReadWrite.All
(The extension will have full access to all SharePoint drives!) - For production environments, add the API permissiones:
Microsoft Graph
->Application permissions
->Sites
->Sites.Selected
.
Refer to these blog posts, on how to grant the extension access to the required sites.
Use Sites.Selected Permission with FullControl rather than Write or Read
Testing out the new Microsoft Graph SharePoint (specific site collection) app permissions with PnP PowerShell
- Find your target drive ID:
- Add a new
Upload files to SharePoint Online
task to your build pipeline. - Fill in all required parameters.
- driveId: SharePoint Online drive ID or URL
(required)
This parameter can hold one of 2 values:- A drive ID from Microsoft Graph. see Microsoft Docs
- The full URL to a SharePoint Online Document Library, e.g.:
https://contoso.sharepoint.com/sites/some-project/Shared%20Documents
- targetFolder: Target folder
(optional, default=none)
This is the target folder relative to the target drive. To copy files to the root of the target drive, leave this parameter empty. You can also use variables here, e.g.:
/build-files/$(Build.BuildID)
The target folder will be created if it does not exist. - sourceFolder: Source folder
(optional, default=none)
The source folder where the task is executed. This acts as a root directory for thecontents
parameter. Leave this parameter empty to use the current working directory of the pipeline.
Important: If you want to copy files outside of the current agent working directory, you must use this parameter to specifiy the new root directory. - contents: Contents to be copied
(required)
Use this parameter to specifiy which files should be uploaded.
**
will upload all files recursively.
build-files/**/*.txt
will copy only txt-files recursively unterbuild-files
These parameters can be found at the application registration page in Azure AD. Microsoft Docs
- tenantId: AzureAD tenant ID
(required) - clientId: AzureAD client ID
(required) - clientSecret: AzureAD client secret
(required)
-
conflictBehaviour: File conflict behaviour
(optional, default: fail)
Specifies how the task should handle a file where the target file already exists. There are 3 different options:
Fail
,Replace
,Rename
For more info see this docs article. -
cleanTargetFolder: Clean Target folder
(optional, default: false)
If set to true, the task will delete all files from the target folder. -
flattenFolders: Flatten Folders
(optional, default: false)
If set to true, all files will be copied to the target folder without retaining the source folder structure. -
failOnEmptySource: Fail if no files found to copy
(optional, default: false)
If set to true, the task will fail if no matching files are found under the source folder.
Parameter source
is left blank to use the current working directory. This copies all files from the dist folder in the current working dir.
steps:
- task: halliba.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint@0
displayName: 'Upload files to SharePoint'
inputs:
tenantId: 'CCCCCCCC-2222-4444-6666-333333333333'
clientId: 'AAAAAAAA-1111-3333-5555-FFFFFFFFFFFF'
clientSecret: '1234567890abcdefghijABCDEFGHIJ1234567890'
driveId: 'https://contoso.sharepoint.com/sites/some-project/Shared%20Documents'
targetFolder: '/build-files/$(Build.BuildId)/'
contents: 'dist/**'
steps:
- task: halliba.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint@0
displayName: 'Upload files to SharePoint'
inputs:
...
sourceFolder: '$(Build.ArtifactStagingDirectory)'
contents: '/bin/**/*.dll'
steps:
- task: halliba.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint.az-pipelines-2-sharepoint@0
displayName: 'Upload files to SharePoint'
inputs:
...
sourceFolder: '/var/some-folder/' #or 'D:\some-folder' for Windows
contents: '**/*.log'
- Due to a limitation (or bug?) of the Microsoft Graph File endpoint you can not upload files with 0-byte size. Those files will be skipped and a warning message is shown.