powershell - Azure Devops - PS 脚本
问题描述
我试图通过 Azure devops Pipeline 在 PS Inline 脚本下运行。但是我在代理日志管道代码上遇到错误:
trigger:
master
pool:
name: 'Dev1'
steps:
task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
New-Item -Path "C:\Manoj" -Force
代理错误:
Starting: PowerShell
Task : PowerShell
Description : Run a PowerShell script on Linux, macOS, or Windows
Version : 2.165.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
Generating script.
========================== Starting Command Output ===========================
"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\tmp\vsts-agent-win-x64-2.165.2_work_temp\65dd1488-c132-4b9a-8403-0604d37f43a4.ps1'"
New-Item : Access to the path 'C:\Manoj' is denied.
At C:\tmp\vsts-agent-win-x64-2.165.2_work_temp\65dd1488-c132-4b9a-8403-0604d37f43a4.ps1:4 char:1
New-Item -Path "C:\Manoj" -Force
+ CategoryInfo : PermissionDenied: (C:\Manoj:String) [New-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand
##[error]PowerShell exited with code '1'.
Finishing: PowerShell
解决方案
该错误表明运行 azdo 代理的帐户无权在系统驱动器的根目录中创建对象。这种限制听起来合乎逻辑,因为代理应该在多用户/多项目场景中服务。
因此,请考虑构建仅在工作目录范围内的管道逻辑。例如:Pipeline.Workspace
trigger:
master
pool:
name: 'Dev1'
steps:
- task: PowerShell@2
inputs:
targetType: inline
script: |
New-Item -Path "$(Pipeline.Workspace)\Manoj" -Force
在这种情况下,不同管道的工件相互隔离。
参考:使用预定义变量
推荐阅读
- c# - .net Core 3.1 C# MVC 非静态字段、方法或属性需要对象引用
- node.js - 在 redux saga 中使用 axios 时出现错误“TypeError: Cannot convert undefined or null to object”
- javascript - 并非所有子元素都会触发 Javascript 中的父元素点击处理程序(不是 preventDefault 问题)
- php - 尝试通过 PHP 将 15k 行 CSV 导入 SQL,但每次只导入 600-900 行
- python - 在 Python 上用这段代码创建一个字典,另一个排序的字典谢谢
- c# - 将旧的 asp 代码转换为 asp.net webform
- python - 使用 Sphinx 时,如何记录没有文档字符串的成员?
- python - AttributeError:“节点”对象没有属性“数据”
- server - 如何获取拥有我的机器人的服务器的所有 ID?我需要获取拥有我的机器人的服务器的所有邀请链接
- python - 两列的 Pandas Drop 功能不起作用