Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何在VSTS中使用外部powershell模块_Git_Powershell_Azure Devops_Azure Pipelines_Alm - Fatal编程技术网

Git 如何在VSTS中使用外部powershell模块

Git 如何在VSTS中使用外部powershell模块,git,powershell,azure-devops,azure-pipelines,alm,Git,Powershell,Azure Devops,Azure Pipelines,Alm,我有下面的构建定义,它安装Chocolate,然后安装posh git 然而,当尝试使用posh git命令时,我遇到了一些问题 下面的日志 2018-05-16T07:26:47.0699610Z ##[section]Starting: Install poshgit 2018-05-16T07:26:47.0702724Z ============================================================================== 2018

我有下面的构建定义,它安装Chocolate,然后安装posh git

然而,当尝试使用posh git命令时,我遇到了一些问题

下面的日志

2018-05-16T07:26:47.0699610Z ##[section]Starting: Install poshgit
2018-05-16T07:26:47.0702724Z ==============================================================================
2018-05-16T07:26:47.0702850Z Task         : Chocolatey - Install Package
2018-05-16T07:26:47.0702946Z Description  : Installs a package using Chocolatey
2018-05-16T07:26:47.0703048Z Version      : 1.1.0
2018-05-16T07:26:47.0703131Z Author       : Jungerius IT
2018-05-16T07:26:47.0703211Z Help         : 
2018-05-16T07:26:47.0703300Z ==============================================================================
2018-05-16T07:26:47.0710435Z Preparing task execution handler.
2018-05-16T07:26:47.2325295Z Executing the powershell script: D:\a\_tasks\ChocoInstallPackage_5a0c2b6f-5503-4ec8-9d79-8d78f31eb1fb\1.1.0\installpackage.ps1
2018-05-16T07:26:49.3669410Z Running Chocolatey version 0.10.10
2018-05-16T07:26:49.3729906Z Adding --confirm to arguments passed to Chocolatey
2018-05-16T07:26:49.4071786Z Installing package poshgit from the Chocolatey package repository...
2018-05-16T07:26:49.9739470Z Chocolatey v0.10.10
2018-05-16T07:26:55.1127680Z Installing the following packages:
2018-05-16T07:26:55.1136686Z poshgit
2018-05-16T07:26:55.1141725Z By installing you accept licenses for the packages.
2018-05-16T07:26:59.1785671Z 
2018-05-16T07:26:59.1786787Z Progress: Downloading poshgit 0.7.3... 11%
2018-05-16T07:26:59.1787047Z Progress: Downloading poshgit 0.7.3... 35%
2018-05-16T07:26:59.1788387Z Progress: Downloading poshgit 0.7.3... 59%
2018-05-16T07:26:59.1790268Z Progress: Downloading poshgit 0.7.3... 83%
2018-05-16T07:26:59.1791434Z Progress: Downloading poshgit 0.7.3... 100%
2018-05-16T07:28:08.7812838Z 
2018-05-16T07:28:08.7813768Z poshgit v0.7.3 [Approved]
2018-05-16T07:28:08.7927753Z poshgit package files install completed. Performing other installation steps.
2018-05-16T07:28:17.2440355Z Downloading poshgit 
2018-05-16T07:28:17.2440890Z   from 'https://github.com/dahlbyk/posh-git/zipball/v0.7.3'
2018-05-16T07:28:17.7319554Z 
2018-05-16T07:28:17.7364572Z Progress: 18% - Saving 13.38 KB of 72.93 KB
2018-05-16T07:28:17.7364998Z Progress: 35% - Saving 25.92 KB of 72.93 KB
2018-05-16T07:28:17.7582093Z Progress: 52% - Saving 38.46 KB of 72.93 KB
2018-05-16T07:28:17.7606506Z Progress: 71% - Saving 51.84 KB of 72.93 KB
2018-05-16T07:28:17.7606825Z Progress: 87% - Saving 63.96 KB of 72.93 KB
2018-05-16T07:28:17.7607100Z Progress: 100% - Completed download of
> C:\Users\VssAdministrator\AppData\Local\Temp\poshgit\0.7.3\dahlbyk-posh-git-v0.7.3-0-g6eb84bd.zip
> (72.93 KB).
2018-05-16T07:28:17.7607357Z Download of dahlbyk-posh-git-v0.7.3-0-g6eb84bd.zip (72.93 KB) completed.
2018-05-16T07:28:20.8109868Z Extracting C:\Users\VssAdministrator\AppData\Local\Temp\poshgit\0.7.3\dahlbyk-posh-git-v0.7.3-0-g6eb84bd.zip
> to C:\tools\poshgit...
2018-05-16T07:28:25.3526959Z WARNING: posh-git repository structure is incompatible with %PSModulePath%.
2018-05-16T07:28:25.3532668Z WARNING: Importing with absolute path instead.
2018-05-16T07:28:25.5758578Z Environment Vars (like PATH) have changed. Close/reopen your shell to
2018-05-16T07:28:25.5759289Z  see the changes (or in powershell/cmd.exe just type `refreshenv`).
2018-05-16T07:28:25.7308461Z  The install of poshgit was successful.
2018-05-16T07:28:25.7312122Z   Software installed to 'C:\tools\poshgit'
2018-05-16T07:28:25.8100731Z 
2018-05-16T07:28:25.8101191Z Chocolatey installed 1/1 packages. 
2018-05-16T07:28:25.8101437Z  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2018-05-16T07:28:25.9812796Z ##[section]Finishing: Install poshgit

2018-05-16T07:28:25.9824530Z ##[section]Starting: PowerShell Script
2018-05-16T07:28:25.9829009Z ==============================================================================
2018-05-16T07:28:25.9829182Z Task         : PowerShell
2018-05-16T07:28:25.9829296Z Description  : Run a PowerShell script
2018-05-16T07:28:25.9829406Z Version      : 1.2.3
2018-05-16T07:28:25.9829514Z Author       : Microsoft Corporation
2018-05-16T07:28:25.9829663Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2018-05-16T07:28:25.9829805Z ==============================================================================
2018-05-16T07:28:26.0156399Z ##[command]. 'C:\Users\VssAdministrator\AppData\Local\Temp\a67e8c43-1d42-422a-84d9-14ecb3e43bb4.ps1'
> 
2018-05-16T07:28:26.7024074Z ##[error]Add-PoshGitToProfile : The term 'Add-PoshGitToProfile' is not recognized as the name of a cmdlet,
> function, script 
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
and try again.
At C:\Users\VssAdministrator\AppData\Local\Temp\a67e8c43-1d42-422a-84d9-14ecb3e43bb4.ps1:1
> char:1
+ Add-PoshGitToProfile
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-PoshGitToProfile:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


2018-05-16T07:28:27.1139427Z ##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.
2018-05-16T07:28:27.1153320Z ##[section]Finishing: PowerShell Script

因此,这里的问题是,您需要在PowerShell脚本步骤中显式地导入模块

虽然看起来您的上一步做了,但这是一个不同的会话,导入仅在该会话范围内有效

此外;如果查看上一步中的警告消息,您会发现:

2018-05-16T07:28:25.3526959Z警告:高级git存储库结构与%PSModulePath%不兼容

2018-05-16T07:28:25.3532668Z警告:改为使用绝对路径导入


正如它所说;使用绝对路径导入,因为模块名称无法正常工作,因为模块格式不正确。

因此这里的问题是,您需要在PowerShell脚本步骤中显式导入模块

虽然看起来您的上一步做了,但这是一个不同的会话,导入仅在该会话范围内有效

此外;如果查看上一步中的警告消息,您会发现:

2018-05-16T07:28:25.3526959Z警告:高级git存储库结构与%PSModulePath%不兼容

2018-05-16T07:28:25.3532668Z警告:改为使用绝对路径导入


正如它所说;使用绝对路径导入,因为模块的格式不正确,因此仅模块名称不起作用。

在使用功能之前,需要运行
导入模块
命令。虽然看起来像是上一步做的,但这是一个不同的会话,导入仅在该会话范围内有效。我也尝试了该选项,不同的错误:。'C:\Users\VssAdministrator\AppData\Local\Temp\e2423137-3cdf-49b7-865d-6c17f2565d57.ps1“导入模块:未加载指定的模块“posh git”,因为在任何以退出代码0完成的模块进程中未找到有效的模块文件,并且出现1个错误写入错误流。您需要运行
导入模块
命令才能使用这些功能。虽然看起来像是上一步做的,但这是一个不同的会话,导入仅在该会话范围内有效。我也尝试了该选项,不同的错误:。'C:\Users\VssAdministrator\AppData\Local\Temp\e2423137-3cdf-49b7-865d-6c17f2565d57.ps1“导入模块:未加载指定的模块“posh git”,因为在任何以退出代码0完成的模块进程中找不到有效的模块文件,并且在错误流中写入了1个错误。如何获取其安装位置的绝对路径?此处?“正在将C:\Users\VssAdministrator\AppData\Local\Temp\poshgit\0.7.3\dahlbyk-posh-git-v0.7.3-0-g6eb84bd.zip解压缩到C:\tools\poshgit…”如何获取安装位置的绝对路径?在这里?“正在将C:\Users\VssAdministrator\AppData\Local\Temp\poshgit\0.7.3\dahlbyk-posh-git-v0.7.3-0-g6eb84bd.zip解压缩到C:\tools\poshgit…”