【问题标题】:Cannot import module from Powershell script using Jenkins无法使用 Jenkins 从 Powershell 脚本导入模块
【发布时间】:2017-11-13 08:43:57
【问题描述】:

我正在尝试使用 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

谁能指出我做错了什么?

【问题讨论】:

    标签: jenkins continuous-integration psake


    【解决方案1】:

    好的,我终于能够解决问题并想分享解决方案,以防其他人遇到问题。运行 Powershell 脚本时,.\ 会自动解析到当前目录。但是,当我们从 Jenkins 执行脚本时,我们需要引用 Jenkins 工作区的路径并使用完整路径。为此,Jenkins 提供了变量 $ENV:WORKSPACE

    我使用的所有地方。\我将其更改为使用 $ENV:WORKSPACE

    所以

    Import-Module .\Psake.4.5.0\psake.psm1变成了

    导入模块 $ENV:WORKSPACE\Build\Psake.4.5.0\psake.psm1

    它开始工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多