Azure devops 使用 devops 中的 powershell 脚本路径任务在 ADLS gen2 容器中分配角色 rwx。

问题描述 投票:0回答:1

我在给存储容器rwx分配角色时遇到一个问题,这样我的数据工厂就可以从adls gen 2中读取数据了。 下面的脚本使用azure devops powershell脚本中的内联脚本运行得很好,但是当我把它改成文件路径的脚本时(位置是github)。我已经把下面的脚本放在.ps1扩展名中了。

[CmdletBinding()]
param(
 [parameter(Mandatory = $false)] [String] $resourcegroup_name,
 [parameter(Mandatory = $false)] [String] $factoryName,
 [parameter(Mandatory = $false)] [String] $storageaccount_name
 )

$principalID = (Get-AzDataFactoryV2 -ResourceGroupName $resourcegroup_name -Name 
$factoryName).identity.PrincipalId
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourcegroup_name -AccountName 
$storageaccount_name
$ctx = $storageAccount.Context
$filesystemName = "adftransformation"
$dirname = "mfg/"
$dir = New-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -Directory - 
Permission r-x -Umask ---rwx---  -Property @{"ContentEncoding" = "UDF8"; "CacheControl" = "READ"}
$acl = (Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname).ACL
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityID $principalID -Permission r-x 
-InputObject $acl 
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -Acl $acl

我在devops管线中得到的错误

2020-06-03T14:29:18.8399468Z ##[错误]无法验证参数 "Permission "的参数。参数 "r-x "不匹配"([r-][w-][x-]){3}"模式。请提供一个与"([r-] [w-][x-]){3}"匹配的参数,并再次尝试该命令。

我不知道为什么在选择脚本作为文件路径的时候会发生这种情况,同样的脚本在内联脚本路径下运行得很好。

enter image description here

github azure-devops azure-data-factory azure-powershell azure-data-lake-gen2
1个回答
0
投票
This is the correct script  from Githubif you are taking as a file path.

[CmdletBinding()]
param(
 [parameter(Mandatory = $false)] [String] $resourcegroup_name,
 [parameter(Mandatory = $false)] [String] $factoryName,
 [parameter(Mandatory = $false)] [String] $storageaccount_name
 )
$principalID = (Get-AzDataFactoryV2 -ResourceGroupName $resourcegroup_name -Name 
$factoryName).identity.PrincipalId
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourcegroup_name - 
AccountName $storageaccount_name
$ctx = $storageAccount.Context
$filesystemName = "fsname"
$dirname = "mfg/"
$dir = New-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname 
-Directory -Permission rwxrwxrwx -Umask ---rwx---  -Property @{"ContentEncoding" = 
"UDF8"; "CacheControl" = "READ"}
$acl = (Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path 
$dirname).ACL
$acl = set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityID $principalID 
-Permission rwx -InputObject $acl 
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname - 
Acl $acl
© www.soinside.com 2019 - 2024. All rights reserved.