GitHub Action
CLI for Microsoft 365 Deploy App
GitHub action to deploy an app using Office 365 CLI
This GitHub Action (created using typescript) uses Office 365 CLI, specifically the spo app add, spo app deploy commands, to add and deploy.
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.
- Office 365 CLI Login – Required . This action is dependant on
action-cli-login
. So in the workflow we need to runaction-cli-login
before using this action.
Since action-cli-login
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. [email protected])adminPassword
- store the password of that user in this. These secrets are encrypted and can only be used by GitHub actions.
APP_FILE_PATH
: Required Relative path of the app in your repoSCOPE
: Scope of the app catalog:tenant|sitecollection
. Default istenant
SITE_COLLECTION_URL
: The URL of the site collection where the solution package will be added. Required if scope is set tositecollection
SKIP_FEATURE_DEPLOYMENT
:true|false
If the app supports tenant-wide deployment, deploy it to the whole tenant. Default isfalse
OVERWRITE
:true|false
Set to overwrite the existing package file. Default isfalse
APP_ID
: The id of the app that gets deployed
On every push
build the code, then login to Office 365 and then start deploying.
name: SPFx CICD with O365 CLI
on: [push]
jobs:
build:
##
## Build code omitted
##
deploy:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
##
## Code to get the package omitted
##
# Office 365 cli login action
- name: Login to tenant
uses: pnp/[email protected]
with:
ADMIN_USERNAME: ${{ secrets.adminUsername }}
ADMIN_PASSWORD: ${{ secrets.adminPassword }}
# Office 365 cli 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: o365clideploy # optional - use if output needs to be used
uses: pnp/[email protected]
with:
APP_FILE_PATH: sharepoint/solution/spfx-o365-cli-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: pnp/[email protected]
with:
APP_FILE_PATH: sharepoint/solution/spfx-o365-cli-action.sppkg
SCOPE: sitecollection
SITE_COLLECTION_URL: https://contoso.sharepoint.com/sites/teamsite
# Option 2 - ends
# Print the id of the app
- name: Get the id of the app deployed
run: echo "The id of the app deployed is ${{ steps.o365clideploy.outputs.APP_ID }}"
If self-hosted runners are used for running the workflow, then please make sure that they have PowerShell
or bash
installed on them.
- Added inital 'Office 365 CLI deploy' GitHub action solving #2
- Fixed 'skipFeatureDeployment not included in spo app deploy command for Windows' solving #4