无法使用 Jenkins 从 Powershell 脚本导入模块
Cannot import module from Powershell script using Jenkins
我正在尝试使用 Psake 在 Jenkins 服务器上构建我的 Asp.Net MVC 解决方案。我已将 Powershell 脚本和 Psake 脚本签入到源代码中。我已经创建了一个引导程序文件 build.ps1 导入并调用 Psake.
导入模块 .\Psake.4.5.0\psake.psm1
Invoke-Psake -buildFile .\default.ps1 `
-taskList Default `
-framework '4.6' `
-parameters @{'solutionFilePath'='..\Application.sln'}
我所有的任务都在我试图调用的 default.ps1 文件中定义。在本地,当我 运行 脚本时,Psake 模块被导入并且一切正常。但是在 Jenkins 服务器上我收到以下错误:
Import-Module : The specified module '.\Psake.4.5.0\psake.psm1' was not loaded
because no valid module file was found in any module directory.At C:\Program
Files (x86)\Jenkins\workspace\Atmosphere\Build\Build.ps1:9 char:1
+ Import-Module .\Psake.4.5.0\psake.psm1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (.\Psake.4.5.0\psake.psm1:S
tring) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
我是 Jenkins 的新手,之前使用过 Team City,我仔细检查过 Psake 模块确实被复制到 Jenkins 工作区。
这就是我从 Jenkins
调用 Build.ps1 的方式
Powershell.exe -noprofile -executionpolicy Bypass -file .\Build\Build.ps1
有人可以指出我做错了什么吗?
好的,我终于能够解决问题,并想分享解决方案以防其他人遇到它。当 运行 Powershell Script .\ 自动解析到当前目录。但是,当我们从 Jenkins 执行脚本时,我们需要引用 Jenkins 工作区的路径并使用完整路径。为此,Jenkins 提供变量 $ENV:WORKSPACE
我在任何地方都使用 .\ 我将其更改为使用 $ENV:WORKSPACE
所以
Import-Module .\Psake.4.5.0\psake.psm1 变成了
导入模块 $ENV:WORKSPACE\Build\Psake.4.5.0\psake.psm1
它开始工作了!
我正在尝试使用 Psake 在 Jenkins 服务器上构建我的 Asp.Net MVC 解决方案。我已将 Powershell 脚本和 Psake 脚本签入到源代码中。我已经创建了一个引导程序文件 build.ps1 导入并调用 Psake.
导入模块 .\Psake.4.5.0\psake.psm1
Invoke-Psake -buildFile .\default.ps1 `
-taskList Default `
-framework '4.6' `
-parameters @{'solutionFilePath'='..\Application.sln'}
我所有的任务都在我试图调用的 default.ps1 文件中定义。在本地,当我 运行 脚本时,Psake 模块被导入并且一切正常。但是在 Jenkins 服务器上我收到以下错误:
Import-Module : The specified module '.\Psake.4.5.0\psake.psm1' was not loaded
because no valid module file was found in any module directory.At C:\Program
Files (x86)\Jenkins\workspace\Atmosphere\Build\Build.ps1:9 char:1
+ Import-Module .\Psake.4.5.0\psake.psm1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (.\Psake.4.5.0\psake.psm1:S
tring) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
我是 Jenkins 的新手,之前使用过 Team City,我仔细检查过 Psake 模块确实被复制到 Jenkins 工作区。
这就是我从 Jenkins
调用 Build.ps1 的方式Powershell.exe -noprofile -executionpolicy Bypass -file .\Build\Build.ps1
有人可以指出我做错了什么吗?
好的,我终于能够解决问题,并想分享解决方案以防其他人遇到它。当 运行 Powershell Script .\ 自动解析到当前目录。但是,当我们从 Jenkins 执行脚本时,我们需要引用 Jenkins 工作区的路径并使用完整路径。为此,Jenkins 提供变量 $ENV:WORKSPACE
我在任何地方都使用 .\ 我将其更改为使用 $ENV:WORKSPACE
所以
Import-Module .\Psake.4.5.0\psake.psm1 变成了
导入模块 $ENV:WORKSPACE\Build\Psake.4.5.0\psake.psm1
它开始工作了!