【问题标题】:YAML Powershell to Update File Permissions FailingYAML Powershell 更新文件权限失败
【发布时间】:2021-07-14 23:46:13
【问题描述】:

Azure DevOps 正在覆盖所需 Web 文件的文件权限。因此,我决定在我的 YAML 管道中添加一个步骤,以确保始终正确设置文件权限。

我使用命令行工具 (CMD) 在服务器上对其进行了测试,效果很好。但是,我将 Step 添加到了 YAML 中,但出现以下异常。

“RX”一词未被识别为 cmdlet、函数的名称, 脚本

  • 我的 YAML 命令行有问题吗?

使用命令行工具 (CMD):
这是我使用 CMD 测试的 RAW 命令行...它工作正常...(RX) parameter 是正确的。

icacls "D:\Applications\MyApplication\bin\Select.Html.dep" /grant:r "mydomain\my_ServiceAccountName_DEV":(RX)

YAML 管道:
命令行(本身)显然是在 PowerShell 中运行的。但我是 YAML 的新手……所以格式可能已经关闭(有点)。有人可以帮忙吗?

#-------------------------------------
#Update File-Permissions for ServiceAccount
- stage: Update_File_Permissions
  jobs:
  - deployment: Update_File_Permissions
    displayName: Update File Permissions
    environment:
      name: 'Purposely Omitted'
      resourceType: 'VirtualMachine'
      tags: 'Purposely Omitted'
    variables:
      DevAppFolder: 'Purposely Omitted'

    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                d:
                cmd /c icacls "D:\Applications\MyApplication\bin\Select.Html.dep" /grant:r "mydomain\my_ServiceAccountName_DEV":(RX)

【问题讨论】:

    标签: powershell azure-devops


    【解决方案1】:

    我们建议您使用“命令行”任务而不是“PowerShell”任务来运行您的脚本:

      - task: CmdLine@2
        inputs:
          script: |
            d:
            icacls "D:\ttt\23.txt" /grant:r "mydomain\mylocaluername":(RX)
    

    它在我的测试中运行良好:

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2014-08-17
      • 2011-07-07
      • 1970-01-01
      相关资源
      最近更新 更多