GitHub action to deploy a SharePoint app using PnP PowerShell.
- Installs PnP PowerShell module
- Connects to the specified site using the Connect-PnPOnline command
- Deploys the app using the Add-PnPApp command
Create a workflow .yml
file in your .github/workflows
directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.
- This action only works with
Windows
Operations System - This action only works for SharePoint Online
Since this action requires user name and password which are sensitive pieces of information, it would be ideal to store them securely. We can achieve this in a GitHub repo by using secrets. So, click on settings
tab in your repo and add 2 new secrets:
adminUsername
- store the admin user name in this (e.g. user@contoso.onmicrosoft.com)adminPassword
- store the password of that user in this. These secrets are encrypted and can only be used by GitHub actions.
SHAREPOINT_SITE_URL
: Required URL of the SharePoint Site.ADMIN_USERNAME
: Required Username of the admin.ADMIN_PASSWORD
: Required Password of the admin.APP_FILE_PATH
: Required Relative path of the app in your repoOVERWRITE
:true|false
Set to overwrite the existing package file. Default isfalse
SCOPE
:Site|Tenant
Scope of the app catalog:Tenant|Site
. Default isTenant
SKIP_FEATURE_DEPLOYMENT
:true|false
If the app supports tenant-wide deployment, deploy it to the whole tenant. Default isfalse
On every push
build the code, deploy the app.
name: SPFx CICD with PnP PowerShell
on: [push]
jobs:
build:
##
## Build code omitted
##
deploy:
needs: build
runs-on: windows-latest
env:
siteUrl: https://contoso.sharepoint.com/sites/teamsite
steps:
##
## Code to get the package omitted
##
# PnP PowerShell deploy app action
# Use either option 1 or option 2
# Option 1 - Deploy app at tenant level
- name: Option 1 - Deploy app to tenant
id: PnPPowerShellDeploy
uses: aakashbhardwaj619/action-pnp-powershell-deploy@v1.0.0
with:
SHAREPOINT_SITE_URL: ${{ env.siteUrl }}
ADMIN_USERNAME: ${{ secrets.adminUsername }}
ADMIN_PASSWORD: ${{ secrets.adminPassword }}
APP_FILE_PATH: sharepoint/solution/spfx-pnp-powershell-action.sppkg
SKIP_FEATURE_DEPLOYMENT: true
OVERWRITE: true
# Option 1 - ends
# Option 2 - Deploy app to a site collection
- name: Option 2 - Deploy app to a site collection
uses: aakashbhardwaj619/action-pnp-powershell-deploy@v1.0.0
with:
SHAREPOINT_SITE_URL: ${{ env.siteUrl }}
ADMIN_USERNAME: ${{ secrets.adminUsername }}
ADMIN_PASSWORD: ${{ secrets.adminPassword }}
APP_FILE_PATH: sharepoint/solution/spfx-pnp-powershell-action.sppkg
# Option 2 - ends