Skip to content

Instantly share code, notes, and snippets.

@anoopt
Last active November 15, 2022 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoopt/a39eac49250079f2cbedb5ccaf841c81 to your computer and use it in GitHub Desktop.
Save anoopt/a39eac49250079f2cbedb5ccaf841c81 to your computer and use it in GitHub Desktop.
# For better pipelines see - https://www.voitanos.io/blog/sharepoint-framework-azure-pipelines-templates/
parameters:
- name: sppkg_file_name
type: string
default: name_of_the_package.sppkg
- name: site_url
type: string
default: https://contoso.sharepoint.com/sites/teamsite
- name: tenant_name
type: string
default: contoso
trigger:
- main
pool: default
jobs:
- job: build_and_deploy
displayName: "Build and deploy"
steps:
- script: npm ci
displayName: Install dependencies
- script: |
gulp bundle --ship
gulp package-solution --ship
displayName: Build and package solution
- powershell: |
$ErrorActionPreference = "Stop"
Write-Host "ℹ️ Getting access token"
$resource = 'https://${{ parameters.tenant_name }}.sharepoint.com'
$response = Invoke-WebRequest -Uri "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$resource" -Headers @{Metadata="true"}
$content = $response.Content | ConvertFrom-Json
$access_token = $content.access_token
Write-Host "ℹ️ Connecting to site"
Connect-PnPOnline ${{ parameters.site_url }} -AccessToken $access_token
Get-PnPWeb
Write-Host "ℹ️ Deploying package"
$sppkgfilePath = '$(Build.SourcesDirectory)/sharepoint/solution/${{ parameters.sppkg_file_name }}'
$addedApp = Add-PnPApp -Path $sppkgfilePath -Scope Site -Overwrite
$addedApp.Id
Write-Host "✅ Done"
displayName: Deploy solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment