Steps below will allow you to publish contents of your Azure VSTS (DevOps) Repo to Sharepoint online and by proxy to OneDrive as well.
There is no built-in task available in either build or release pipeline to push files to OneDrive so solution below relies on Azure Logic Apps to perform those functions.
Overall flow is below
- Azure DevOps completes build which packages code in ZIP file as build artifact
- Azure DevOps project calls Azure Logic App webhook
- Azure Logic App retrieves results of build task and extracts to Sharepoint online documents folder
Steps in detail:
Create build pipeline in Azure Devops
Yaml file as well as UI representation is below. It packages files in scripts
folder into ZIP file into subfolder called Powershell Scripts
pool: | |
vmImage: Hosted VS2017 | |
steps: | |
– task: CopyFiles@2 | |
displayName: 'Copy Files to: $(build.artifactstagingdirectory)' | |
inputs: | |
SourceFolder: scripts | |
TargetFolder: '$(build.artifactstagingdirectory)' | |
– task: PublishBuildArtifacts@1 | |
displayName: 'Publish Artifact: Powershell Scripts' | |
inputs: | |
ArtifactName: 'Powershell Scripts' | |
Create Azure LogicApp
Define a trigger of HTTP request type. Use following Request Body Schema. You can download schema from here https://gist.github.com/artisticcheese/2b5410ee65bc7b76273fdef47edd0c4b
Save trigger which will give you HTTP Post URL which you would need to use later in Azure DevOps project
Since you might have more then 1 build in your Azure Devops pipeline you need to have conditional logic in your LogicalApp to only publish on results of specific buildID.
Second step in LogicApp is “Condition” based on definition id
number of your build. In my case it’s 5
Next steps are initialize 2 variable. First one will be holding buildID number as well authorization information for AzureDevops.
To create Authorization token you need to create PAT token in AzureDevops and encode :{token}
into Base64. For example if my PAT token is a123
then go to https://www.base64encode.org/ and encode value of :a123
into OmExMjM=
Add Send an HTTP Request to Azure Devops as next step and modify parameters respectively for your values. Output of this step will allow to get URL to download artifact.
Add 2 steps to parse JSON and extract value of downloadURI. Schema can be download from here https://gist.github.com/artisticcheese/0cf1d9c4b35e9fe3d01ea408555c3d15
Last 3 steps are downloading artifact from URL and extracting it to Sharepoint site
Add webhook to AzureDevops
Go to project settings and add a service hook
Enter webhook URI you get in previous steps for LogicApp
Hi
Thanks for a great guide!
IS it possible to pass the Artifact name as parameter?
Thanks
LikeLike