This task will enable you to upload file(s) to a SharePoint Document library from a Build or a Release Pipeline.
Pre-requisite
- Azure DevOps Pipeline
- PowerShell Task
- Azure Key Vault
- SharePoint Site
Setup
-
Create the following Variables for your pipeline
Variable Description $SPUsername The user account using which you will connect to SharePoint. It is recommended to use Variable Groups connected to Azure Key Vault to store credentials. $SPPassword You may need to use App Passwords instead of password for Multi-factor authentication (MFA). Generate App password using this link. It is recommended to use Variable Groups connected to Azure Key Vault to store credentials. $SPURL The SharePoint site URL $SPFolder SharePoint Library folder where you want to upload the files to $Folder Folder from which you want to upload files. This can be the release or build staging directory also. -
Add a new PowerShell task to your Pipeline
Classic

YAML

-
You can use this script as an
Inline Scriptor from aFile Path. Use one of the following script depending on your selection -
Call the script
Inline
Replace the variables enclosed in curly braces
{ VariableName }with your variablesAdd-FilesToSP -Version "Online" -Username { SPUserName } -Password { SPPassword } -URL { SPURL } -SPFolder { SPFolder } -Folder { Folder }It should look something like this
Add-FilesToSP -Version "Online" -Username $SPUsername -Password $SPPassword -URL $SPURL -Folder $FolderFile Path
Pass the variables as arguments after selecting the script file
-SPVersion "Online" -SPUsername $SPUsername -SPPassword $SPPassword -SPURL $SPURL -SPFolder $SPFolder -Folder $FolderClassic

YAML
- task: PowerShell@2 inputs: filePath: '.\uploadToSharePointInFilePath.ps1' arguments: '-SPVersion "Online" -SPUsername $SPUsername -SPPassword $SPPassword -SPURL $SPURL -SPFolder $SPFolder -Folder $Folder'
For Version parameter Online is for SharePoint Online, 2013 for SharePoint 2013, 2016 for SharePoint 2016 and 2019 for SharePoint 2019
Output
Pipeline Logs

Uploaded File

Feel free to customize the script to suit your needs, the script provided here serves only as template.