gpt4 book ai didi

azure - 在 Azure DevOps 管道中的 PowerShell 中使用参数

转载 作者:行者123 更新时间:2023-12-02 23:23:35 25 4
gpt4 key购买 nike

我们最近开始使用 Azure DevOps Pipelines 来实现 Dynamics 365 CRM,但它对我来说仍然是新鲜事

我最近遇到了this Joe Griffin 撰写的博客文章,介绍如何在 Azure DevOps 管道中使用 PowerShell,以确保访问团队模板在部署解决方案时有效 - 我想使用它。

但是,我不知道在哪里将参数添加到脚本中。我可以内联执行此操作还是需要将脚本添加到我的存储库中才能执行此操作?如果是这样 - 我该怎么做?

param(
#objectTypeCode: Unique Code that identifies the table in the environment for the Access Team Template. Always potentially different.
[Parameter(Mandatory=$true)]
[int]$objectTypeCode,
#atName: Name of the Access Team Template
[Parameter(Mandatory=$true)]
[String]$atName,
#accessRights: Number which represents the access rights defined for the template. Refer to this article for details on how to construct: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/accessrights?view=dynamics-ce-odata-9
[Parameter(Mandatory=$true)]
[int]$accessRights,
#d365URL: URL of the environment to connect to
[Parameter(Mandatory=$true)]
[String]$d365URL,
#clientID: AAD Client ID for the Application User linked to this environment
[Parameter(Mandatory=$true)]
[String]$clientID,
#clientSecret: AAD Client Secret for the Application User linked to this environment
[Parameter(Mandatory=$true)]
[String]$clientSecret
)

#Install dependencies
Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser -Force
#Connect to the D365 environment
$conn = Connect-CrmOnline -ServerUrl $d365URL -ClientSecret $clientSecret -OAuthClientId $clientID -OAuthRedirectUri "http://localhost"
#We first attempt to retrieve the rows if they already exist, and update it accordingly; if this errors, then the row does not exist, so we need to create it instead
Write-Host "Processing Access Team Template for $atName..."
try
{
$atTemplate = Get-CrmRecord -conn $conn -EntityLogicalName teamtemplate -Id "44396647-CEDF-EB11-BACB-000D3A5810F2" -Fields teamtemplateid,teamtemplatename,objecttypecode,defaultaccessrightsmask,issystem
$atTemplateId = $atTemplate.teamtemplateid
Write-Host "Got existing Access Team Template row with ID $atTemplateId!"
$atTemplate.teamtemplatename = $atName
$atTemplate.objecttypecode = $objectTypeCode
$atTemplate.defaultaccessrightsmask = $accessRights
$atTemplate.issystem = 0
Set-CrmRecord -conn $conn -CrmRecord $atTemplate
Write-Host "Successfully updated Access Team Template row with ID $atTemplateId!"
}
catch [System.Management.Automation.RuntimeException]
{
Write-Host "Access Template row with ID $atTemplateId does not exist, creating..."
$atTemplateId = New-CrmRecord -conn $conn -EntityLogicalName teamtemplate `
-Fields @{"teamtemplateid"=[guid]"{44396647-CEDF-EB11-BACB-000D3A5810F2}";"teamtemplatename"=$atName;"objecttypecode"=$objectTypeCode;"defaultaccessrightsmask"=$accessRights;"issystem"=0}
Write-Host "Successfully created new Access Template row with ID $atTemplateId"
}
Write-Host "Script execution finished!"

最佳答案

您可以在 yaml 中添加 Powershell 任务并调用 Powershell 脚本来执行所需的任务。脚本参数可以在 DevOps 库中设置和传递。

    - task: AzurePowerShell@5
displayName: 'Powershell task'
inputs:
azureSubscription: '${{ parameters.ServiceConn }}'
ScriptType: 'FilePath'
ScriptPath: '[Path to script]/PowershellScriptName.ps1'
ScriptArguments: '-objectTypeCode $(objectTypeCode) -atName $(atName) -accessRights $(accessRights) -d365URL $(d365URL) -clientID $(clientID) -clientSecret $(clientSecret)'
azurePowerShellVersion: 'LatestVersion'
pwsh: true

关于azure - 在 Azure DevOps 管道中的 PowerShell 中使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69356649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com