Skip to content

Instantly share code, notes, and snippets.

@pankajsurti
Created Mar 14, 2022
Embed
What would you like to do?
parameters:
# unique name of the job
job_name: deploy_sppkg
# friendly name of the job
display_name: Upload & deploy *.sppkg to SharePoint app catalog
# agent pool details (default: MSFT hosted Ubuntu)
pool: Default
# vmImage: ubuntu-latest
# name of target enviroment deploying to
target_environment: ''
# o365 user credentials
o365_client_id: ''
o365_client_secret: ''
# app catalog url
o365_app_catalog_site_url: ''
# app catalog scope (tenant|sitecollection)
o365cli_app_catalog_scope: ''
# additional arguments to add to execution of o365cli
o365cli_spoAppAdd_extra_arguments: ''
o365cli_spoAppDeploy_extra_arguments: ''
# node version
node_version: '10.x'
jobs:
- deployment: ${{ parameters.job_name }}
displayName: ${{ parameters.display_name }}
pool: ${{ parameters.pool }}
environment: ${{ parameters.target_environment }}
strategy:
runOnce:
deploy:
steps:
##########################################
## download previously built *.sppkg
##########################################
- task: DownloadBuildArtifacts@0
displayName: Download SharePoint package (*.sppkg)
inputs:
buildtype: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
##########################################
## determine name of generated *.sppkg
##########################################
- task: PowerShell@2
displayName: Get generated *.sppkg filename
name: GetSharePointPackage
inputs:
targetType: 'inline'
script: |
$CMD_GET_SPPKG_NAME = Get-ChildItem '*.sppkg' -Recurse | Select FullName
$CMD_GET_SPPKG_NAME = $CMD_GET_SPPKG_NAME.FullName
echo "##vso[task.setvariable variable=SpPkgFileName;isOutput=true]$CMD_GET_SPPKG_NAME"
echo $CMD_GET_SPPKG_NAME
##########################################
## upload *.sppkg to the target app catalog
##########################################
- script: echo "$(GetSharePointPackage.SpPkgFileName)"
- task: PowerShell@2
displayName: Upload SharePoint package to Site Collection App Catalog
inputs:
targetType: 'inline'
script: |
Write-Host "Start of the script"
#$pkgPath = $(GetSharePointPackage.SpPkgFileName)
#Write-Host "Deploy " + "$(GetSharePointPackage.SpPkgFileName)"
Write-Host "Install PnP.PowerShell"
Install-Module -Name "PnP.PowerShell" -Force
$SiteUrl = "${{ parameters.o365_app_catalog_site_url }}"
Write-Host "Connect to $SiteUrl"
$argHashTable = @{
"Url" = "${{ parameters.o365_app_catalog_site_url }}"
"ClientId" = "${{ parameters.o365_client_id }}"
"ClientSecret" = "${{ parameters.o365_client_secret }}"
}
$conn = Connect-PnPOnline @argHashTable -ReturnConnection
Write-Host "Connection is $conn"
Write-Host "Call Add-PnPApp"
Add-PnpApp -Path "$(GetSharePointPackage.SpPkgFileName)" -Scope Site -Overwrite -Publish -Connection $conn
Write-Host "Add-Pnp is successfull"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment