如何使用github操作从Powershell脚本进行部署?

时间:2020-06-30 17:49:16

标签: powershell sharepoint-online github-actions spfx

我尝试使用GitHub动作在每次推送到GitHub存储库时将其部署到siteCollection appcatalog。看到可以使用Office 365 CLI操作,但这仅允许租户管理员进行部署。

在运行Powershell脚本之前,需要构建并创建.sppkg文件。 因此,我在GitHub操作中使用了PowerShell的 SharePointPnPPowerShellOnline 模块。我能够连接到该站点。

我找不到访问.sppkg文件并将其部署到网站的方法

文件夹结构

VSCode Folder Tree

下面是我的代码

Install-Module -Name SharePointPnPPowerShellOnline -Force -Verbose -Scope CurrentUser

$siteUrl = "https://test.sharepoint.com"
$username = "xyz@abc.com" 
$password = "myPassword"      

$encpassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword

Connect-PnPOnline -Url $siteUrl -Credentials $cred

Write-Host "logged in"

#code to access the sppkg file and deploy it to the site collection appcatalog

--------------------------------------------------------------------------------
$getTheSPPKGFile = *************

Add-PnPApp -Path $theSPPKGFile -Publish -Overwrite
--------------------------------------------------------------------------------

任何搜索都会导致租户管理方法。我没有租户管理员访问权限,只有网站集管理员访问权限。

谢谢

1 个答案:

答案 0 :(得分:1)

我今天可以使用Github Actions和PnP powershell实现此目标,而无需任何O365 CLI步骤。

我还创建了一个ps1文件,其中包含用于安装PnP powershell模块以及使用PnP powershell将应用程序部署到目标站点的代码。

这两个文件都可以在我的存储库中找到:

yml file deployment script

我的存储库中分支的路径是以下路径:

my repository in github

关键是要运行PnP powershell,您需要使用Windows运行程序,并在运行步骤的shell参数中将shell名称用作“ powershell”。

关于已下载软件包的路径,您可以使用上载工件和下载工件步骤以及以下表达式来获得下载工件的路径:$ {{steps.packageDownloadStep.outputs.download-path}}其中“ packageDownloadStep”是赋予sppkg文件的下载工件步骤的ID。可以在yml文件中检查。

将在存储库的根目录(与gulpfile.js相同的文件夹中)中检查部署脚本(ps1)。您可以在我上面共享的存储库分支中检查结构。