简体   繁体   English

如何使用 github 动作从 powershell 脚本部署?

[英]How to deploy from powershell script using github actions?

I am trying to deploy to siteCollection appcatalog on each push to my GitHub repository using GitHub actions.我正在尝试使用 GitHub 操作在每次推送到我的 GitHub 存储库时部署到 siteCollection appcatalog。 Saw that it's possible using Office 365 CLI action, but that only allows tenant admins to deploy.看到可以使用Office 365 CLI操作,但这仅允许租户管理员进行部署。

Before I run the powershell script I build and create the .sppkg file.在我运行 powershell 脚本之前,我构建并创建了.sppkg文件。 So I used PowerShell's SharePointPnPPowerShellOnline Module in GitHub actions.所以我在 GitHub 动作中使用了 PowerShell 的SharePointPnPPowerShellOnline模块。 I was able to connect to the site.我能够连接到该站点。

I'm not able to find a way to access the .sppkg file and deploy it to the site我无法找到访问.sppkg文件并将其部署到站点的方法

Folder structure文件夹结构

VSCode 文件夹树

Below is my code下面是我的代码

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
--------------------------------------------------------------------------------

Any search is resulting to tenant admin approach.任何搜索都会导致租户管理员方法。 I don't have tenant admin access, only site collection admin access.我没有租户管理员访问权限,只有网站集管理员访问权限。

Thank you谢谢

I was able to achieve this today using Github Actions and PnP powershell without any O365 CLI step.我今天能够使用 Github Actions 和 PnP powershell 实现这一目标,而无需任何 O365 CLI 步骤。

I also created a ps1 file which contains code to install PnP powershell module and to deploy app to the target site using PnP powershell.我还创建了一个 ps1 文件,其中包含安装 PnP powershell 模块并使用 PnP powershell 将应用程序部署到目标站点的代码。

Both the files can be seen in my repository here:这两个文件都可以在我的存储库中看到:

yml file deployment script yml 文件部署脚本

The path to the branch in my repository is this one:我的存储库中分支的路径是这个:

my repository in github 我在 github 中的存储库

The key thing here is that for PnP powershell to run, you would need to use a windows runner and use the shell name as 'powershell' in the shell parameter of the run step. The key thing here is that for PnP powershell to run, you would need to use a windows runner and use the shell name as 'powershell' in the shell parameter of the run step.

Regarding the path of the downloaded package, you can get it by using upload artifact and download artifact steps and this expression to get the path where artifact is downloaded: ${{steps.packageDownloadStep.outputs.download-path}} where 'packageDownloadStep' is the id given to the download-artifact step for the sppkg file.关于下载的package的路径,可以通过上传artifact和download artifact步骤和这个表达式获取artifact的下载路径:${{steps.packageDownloadStep.outputs.download-path}} where 'packageDownloadStep'是 sppkg 文件的下载工件步骤的 ID。 This can be checked in the yml file.这可以在 yml 文件中检查。

The deployment script (ps1) will be checked in the repository at the root, in the same folder as gulpfile.js.部署脚本 (ps1) 将在根目录中的存储库中检查,与 gulpfile.js 位于同一文件夹中。 You can check the structure in the branch of my repository which I have shared above.您可以检查我在上面共享的存储库分支中的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM