Wednesday, August 14, 2019

Azure Devops Automate building of SharePoint Apps

Problem-Scenario:

In Azure Devops there are .net related templates available for use in build definition but there isn't anything available for building SharePoint apps

Solution:
There isn't an inbuilt template available for building SharePoint apps. So i had improvise.

After trying different options, I was able to use yml code to build pipeline for SharePoint hosted apps. 
There aren’t any inbuilt templates available for SP hosted apps.

Background: 
Our sharepoint hosted app's source code is stored in azure Repos. Repo is used as an input to build pipeline. Use minimal starter yml and then update based on the information in this blog.

Below are the main steps to remember:
Also attached is the complete yaml file at the end

Trigger

 
You can mention committing to which branch will trigger the build pipeline. You can also configure it to exclude some branches or sub-branches.


Build SP Hosted app


Ignore the script step. This just displays the internal location of directories.

Used MSBuild to build our SharePoint app Repo and output .APP file


Copy files to artifact staging directory





Copies the output for publishing
FlattenFolders: true --> Flattens the folder structure
Contents: 'app.publish/**/*.app' --> filters *.app file


Publishing the artifact









Where does the artifacts go? Or how to access it?

Open build result & look at snapshot below:





The folder structure can be changed if needed.

This is saved for each build that is run and is retained as per our retention policy.

This artifact, in turn, will directly consumed by RELEASE pipeline which can either be triggered automatically or manually.



Below is the entire .yml file for your ease of use.


# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master


pool:
vmImage: 'windows-latest'

variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'

steps:
- script: echo Hello, world!DA1S $(Build.SourcesDirectory) and agent da1 is $(Agent.BuildDirectory) AND $(System.DefaultWorkingDirectory)/bin/
displayName: 'Run a one-line script'

- task: MSBuild@1
inputs:
solution: '$(solution)'
msbuildArguments: '/t:Package /p:OutputPath=$(Build.SourcesDirectory)/bin/'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)/bin/'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
ArtifactName: 'drop'
PathtoPublish: '$(Build.SourcesDirectory)/bin/'

No comments: