【问题标题】:Azure devops assigment of roles rwx in ADLS gen2 container using powershell script path task in devopsAzure devops 使用 devops 中的 powershell 脚本路径任务在 ADLS gen2 容器中分配角色 rwx
【发布时间】:2020-06-11 17:29:51
【问题描述】:

我在将角色分配给存储容器 rwx 时面临一个问题,以便我的数据工厂可以 从 adls gen 2 读取数据。下面的脚本在 azure devops 中使用内联脚本运行良好 电源外壳 script.But 当我从文件路径(位置是 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 ##[错误]无法验证参数 参数“权限”。这 参数“r-x”与“([r-][w-][x-]){3}”模式不匹配。提供一个匹配 "([r-] [w-][x-]){3}" 并再次尝试该命令。

我不确定为什么在选择脚本作为文件路径时会发生这种情况,相同的脚本在 内联脚本路径

【问题讨论】:

  • 我检查了 ADSL gen2 文档并注意到 r-x 权限是有效的。但从错误信息来看,似乎无法读取。此问题似乎与 Azure Powershell 脚本本身有关。虽然我对这个脚本不熟悉,但还是想给一点建议。您可以尝试在r-w 上添加引号(例如-Permission "rw-")。
  • 我已经试过了,并且脚本在内联脚本中运行良好。唯一的问题是,当我从 scipt 文件路径(git)中获取相同的脚本时,它会产生语法 rwx 的问题。
  • 为了缩小这个问题,您可以直接使用Azure PowershellAzure上运行ps脚本文件,然后检查它是否可以工作。这样就可以判断问题的原因是脚本本身还是azure devops文件读取步骤。
  • Hello Kevin 问题在于权限中的语法 -- rwx -- 我删除了 -- 它工作正常。
  • 很高兴知道您已经解决了这个问题。也许您可以与我们分享解决方案。然后你可以accept your answer。在这种情况下,其他人可以直接找到有用的解决方案。

标签: github azure-devops azure-data-factory azure-powershell azure-data-lake-gen2


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 2020-09-07
    • 2020-12-09
    • 2021-09-14
    • 1970-01-01
    • 2021-12-04
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多