简体   繁体   English

无法在 Azure DevOps 存储库上使用 Powershell 模块

[英]Unable to use Powershell Module on Azure DevOps Repo

I have a powershell script that runs fine in my local but it wont run on the Azure DevOps Pipeline by Committing the script in the repo.我有一个 powershell 脚本,它在我的本地运行良好,但它不会在 Azure DevOps 管道上运行,方法是在仓库中提交脚本。 The script include multiple.psm1 Modules and it seems like devOps cant find the module.该脚本包含多个.psm1 模块,似乎 devOps 无法找到该模块。 I tried committing the module files on the repo and Calling it via Import-Module but its still the same error我尝试在 repo 上提交模块文件并通过 Import-Module 调用它,但它仍然是相同的错误

It's difficult for me to answer the questions.我很难回答这些问题。 It would be nice to have more screenshots, paths, details and environment, but I can tell you how I would do it.有更多的截图、路径、细节和环境会很好,但我可以告诉你我会怎么做。

1) The example is based on ASP.NET project where I added ps1 script with psm1 module to the main project path. 1) 该示例基于 ASP.NET 项目,其中我将带有 psm1 模块的 ps1 脚本添加到主项目路径。 2) I pushed everything to the Azure Devops repo. 2) 我将所有内容推送到 Azure Devops 存储库。 3) I used Inline script to run the ps1 script: 3)我使用内联脚本来运行 ps1 脚本:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: '$(BUILD.REPOSITORY.LOCALPATH)\$(SYSTEM.TEAMPROJECT)\testScript.ps1'

4) In the script I used local path 4)在脚本中我使用了本地路径

Import-Module -Name ./testModule.psm1 -Verbose -ArgumentList 'Argument1'

And it worked.它奏效了。

PS. PS。

You can use powershell inline script to look at your azure devops variables您可以使用 powershell 内联脚本来查看您的 azure devops 变量

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'get-childitem -path env:*'

Using this information you can use powershell inline script to look for your PS1/PSM1 files:使用此信息,您可以使用 powershell 内联脚本来查找您的 PS1/PSM1 文件:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'ls $(BUILD.REPOSITORY.LOCALPATH)\$(SYSTEM.TEAMPROJECT)'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Azure DevOps 中使用 SharePointPnpPowerShellOnline PowerShell 模块? - How to use SharePointPnpPowerShellOnline PowerShell module in Azure DevOps? 尝试使用 Powershell 从 Azure DevOps Git 存储库下载文件 - Trying to download a file from an Azure DevOps Git repo using Powershell 如何将 Powershell 脚本文件路径从 azure devops repo 传递到 Azure devops 构建管道 - how to pass Powershell script filepath from azure devops repo into Azure devops build pipeline 在 Azure DevOps 管道中的 PowerShell 中使用参数 - Use parameter in PowerShell in Azure DevOps pipeline 无法在 Azure DevOPS 中资源组部署任务的覆盖参数中使用来自 PowerShell 脚本的输出变量 - Unable to use output variables from a PowerShell script in the Override Parameters of a Resource Group deployment task in Azure DevOPS Azure DevOps PowerShell 任务无法加载“Az.CosmosDB”模块 - Azure DevOps PowerShell task fails to load 'Az.CosmosDB' module 您可以在 Azure Azure Devops 的内联脚本中使用 IF 语句吗? - can you use IF statement in inline Azure Powershell script in Azure Devops? 在 azure-pipelines.yml powershell 脚本中使用 Azure Devops 变量 - Use Azure Devops variable in azure-pipelines.yml powershell script 如何使用 powershell/Azure CLI 列出对 Azure DevOps 项目 repo 具有权限的用户? - How to list the user who has permissions to the Azure DevOps project repo with powershell/ Azure CLI? 无法在 Azure Devops 中使用 PowerShell 任务获取令牌 - Unable to acquire token using PowerShell task in Azure Devops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM