我有以下Build Definition,它安装了chocolatey,然后安装了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
答案 0 :(得分:2)
因此,问题在于您需要在PowerShell脚本步骤中明确Import-Module
。
虽然看起来你的上一步做了 - 那是一个不同的会话,导入只在该会话范围内有效。
此外;如果你查看上一步的警告信息,你会发现这一点:
2018-05-16T07:28:25.3526959Z警告:posh-git存储库结构与%PSModulePath%不兼容。
2018-05-16T07:28:25.3532668Z警告:改为使用绝对路径导入
正如它说的那样;使用绝对路径导入仅作为模块名称将无法正常运行,因为模块格式不正确。