2

在我的个人资料下运行命令和 TeamCity 运行相同命令之间出现了一些奇怪的行为。

> Import-Module $root\packages\fsm.buildrelease.*\tools\modules\BuildDeployModules -Force

如果我手动运行脚本,构建将按预期开始。如果我让 TeamCity 执行脚本,它会出现以下内容。

Import-Module :未加载指定的模块“C:\BuildAgent\work\81eb7c2fdfcfc0af\packages\fsm.buildrelease.*\tools\modules\BuildDeployModules”,因为在任何模块目录中都找不到有效的模块文件。

我已经两次和三次验证该模块是否存在于该位置。而且我已经浏览了我的模块并[cmdletbinding()]在 之前添加了param,但它似乎并没有解决这个问题。

这很令人沮丧,因为它没有说明“哪个”模块传入了无效参数。


$fsmbrVersion = "1.1.1" # contains the current version of fsm.buildrelease

Write-Host "`nfsm.buildrelease version $fsmbrVersion `nCopyright ($([char]0x00A9)) Future State Mobile Inc. & Contributors`n"

Push-Location $psScriptRoot

. .\Add-HostsFileEntry.ps1
. .\Add-IISHttpVerb.ps1
. .\Add-IISMimeType.ps1
. .\Add-LoopbackFix.ps1
. .\ApplicationAdministration.ps1
. .\AppPoolAdministration.ps1
. .\Approve-Permissions.ps1
. .\Assert-PSVersion.ps1
. .\EntityFramework.ps1
. .\Expand-NugetPackage.ps1
. .\Expand-ZipFile.ps1
. .\Format-TaskNameToHost.ps1
. .\Get-EnvironmentSettings.ps1
. .\Grunt.ps1
. .\Helpers.ps1
. .\Install-WebApplication.ps1
. .\Invoke-Deployment.ps1
. .\Invoke-DeployOctopusNugetPackage.ps1
. .\Invoke-ElevatedCommand.ps1
. .\Invoke-ExternalCommand.ps1
. .\Invoke-Using.ps1
. .\MSBuild.ps1
. .\Nuget.ps1
. .\nUnit.ps1
. .\Set-IISAuthentication.ps1
. .\Set-IISCustomHeader.ps1
. .\SiteAdministration.ps1
. .\Specflow.ps1
. .\SqlHelpers.ps1
. .\Test-PathExtended.ps1
. .\Test-RunAsAdmin.ps1
. .\TextUtils.ps1
. .\Update-AssemblyVersions.ps1
. .\Update-JsonConfigFile.ps1
. .\Update-XmlConfigFile.ps1
. .\WindowsFeatures.ps1
. .\xUnit.ps1

Pop-Location

Export-ModuleMember `
    -Alias @(
        '*') `
    -Function @(
          'Add-HostsFileEntry',
          'Add-IISHttpVerb',
          'Add-IISMimeType',
          'Add-LoopbackFix',
          'Approve-Permissions',
          'Assert-That',
          'Assert-PSVersion',
          'Confirm-ApplicationExists',
          'Confirm-AppPoolExists',
          'Confirm-SiteExists',
          'Exec',
          'Expand-NugetPackage',
          'Expand-ZipFile',
          'Format-TaskNameToHost',
          'Get-Application',
          'Get-Applications',
          'Get-AppPool',
          'Get-AppPools',
          'Get-DatabaseConnection',
          'Get-EnvironmentSettings',
          'Get-Site',
          'Get-Sites',
          'Get-TestFileName',
          'Get-WarningsFromMSBuildLog', 
          'Get-WindowsFeatures',
          'Install-WebApplication',
          'Install-WindowsFeatures',
          'Invoke-BulkCopy',
          'Invoke-DBMigration',
          'Invoke-Deployment',
          'Invoke-DeployOctopusNugetPackage',
          'Invoke-ElevatedCommand',
          'Invoke-EntityFrameworkMigrations',
          'Invoke-ExternalCommand',
          'Invoke-FromBase64', 
          'Invoke-GruntMinification',
          'Invoke-HtmlDecode', 
          'Invoke-HtmlEncode',
          'Invoke-KarmaTests',
          'Invoke-MSBuild',
          'Invoke-Nunit',
          'Invoke-NUnitWithCoverage'
          'Invoke-SpecFlow',
          'Invoke-SqlFile',
          'Invoke-SqlStatement',
          'Invoke-ToBase64', 
          'Invoke-UrlDecode', 
          'Invoke-UrlEncode', 
          'Invoke-Using',
          'Invoke-XUnit',
          'Invoke-XUnitWithCoverage',
          'New-Application',
          'New-AppPool',
          'New-NugetPackage',
          'New-Site',
          'Remove-Application',
          'Remove-AppPool',
          'Remove-Site',
          'RequiredFeatures',
          'Set-IISAuthentication',
          'Set-IISCustomHeader',
          'Start-Application',
          'Start-AppPool',
          'Start-Site',
          'Step',
          'Stop-Application',
          'Stop-AppPool',
          'Stop-Site',
          'Test-PathExtended',
          'Test-RunAsAdmin',
          'Update-Application',
          'Update-AppPool',
          'Update-AssemblyVersions',
          'Update-JsonConfigValues',
          'Update-Site',
          'Update-XmlConfigValues'
          )


# Messages
DATA msgs {
convertfrom-stringdata @"
    error_duplicate_step_name = Step {0} has already been defined.
    error_must_supply_a_feature = You must supply at least one Windows Feature.
    error_feature_set_invalid = The argument `"{0}`" does not belong to the set `"{1}`".
    error_admin_required = You are required to 'Run as Administrator' when running this deployment.
    error_loading_sql_file = Error loading '{0}'. {1}.
    error_octopus_deploy_failed = Failed to deploy: {0}.
    error_specflow_failed = Publishing specflow results  for '{0}' failed.
    error_coverage_failed = Running code coverage for '{0}' failed.
    error_tests_failed = Running tests '{0}' failed.
    error_msbuild_compile = Error compiling '{0}'.
    wrn_full_permission = You have applied FULL permission to '{0}' for '{1}'. THIS IS DANGEROUS!
    wrn_cant_find = Could not find {0} with the name: {0}.
    msg_grant_permission = Granting {0} permissions to {1} for {2}.
    msg_enabling_windows_feature = Enabling Windows Feature: `"{0}`".
    msg_wasnt_found = `"{0}`" wasn't found.
    msg_updated_to = Updated `"{0}`" to `"{1}`".
    msg_updating_to = Updating `"{0}`" to `"{1}`".
    msg_changing_to = Changing `"{0}`" to `"{1}`".
    msg_overriding_to = Overriding node `"{0}`" with value `"{1}`".
    msg_updating_assembly = Updating AssemblyVersion to '{0}'. Updating AssemblyFileVersion to '{1}'. Updating AssemblyInformationalVersion to '{2}'.
    msg_not_updating = Not updating {0}, you must specify the '-updateIfFound' if you wish to update the {0} settings.
    msg_custom_header = Setting custom header '{0}' on site '{1}' to value '{2}'.
    msg_disable_anon_auth = Disabling Anonymous Authentication for '{0}'.
    msg_web_app_success = Successfully deploy Web Application '{0}'.
    msg_copying_content = Copying {0} content to {1}.
    msg_use_machine_environment = Using config for machine {0} instead of the {1} environment.
    msg_octopus_overrides = Checking for Octopus Overrides for environment '{0}'.
    msg_teamcity_importdata = ##teamcity[importData type='{0}' tool='{1}' path='{2}']
    msg_teamcity_buildstatus = ##teamcity[buildStatus text='{0}']
    msg_teamcity_buildstatisticvalue = ##teamcity[buildStatisticValue key='{0}' value='{1}']
    msg_add_loopback_fix = Adding loopback fix for '{0}'.
    msg_add_mime_type = Adding mime type '{0}' for extension '{1}' to IIS site '{2}'.
    msg_add_verb = Adding IIS Http Verb '{0}' to site '{1}'.
    msg_add_host_entry = Adding host entry for '{0}' into the hosts file.
    msg_validate_host_entry = Validating host entry for '{0} in the hosts file'
    msg_loopback_note = note: we're not disabling the loopback check all together, we are simply adding '{0}' to an allowed list.
"@
}
4

1 回答 1

0

问题与导入模块无关;powershell 在引导您解决问题方面不是很有帮助。-VERBOSE直到我把开关放在导入上,问题的根源才暴露出来。一旦我这样做了,我就会在旧错误之上得到一个新错误。

: 参数属性需要是常量或者脚本块。
FullyQualifiedErrorId: ParameterAttributeArgumentNeedsToBeConstandOrScriptBlock

本质上,我使用ValidatePattern的是双引号而不是单引号。检查并确保您在使用时正确编写正则表达式模式ValidatePattern

# Bad
[ValidatePattern("^[a-z]$")]

# Good
[ValidatePattern('^[a-z]$')]
于 2015-02-28T03:02:26.577 回答