Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.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
Azure管道崩溃了在本地正常运行的pwsh脚本_Azure_Docker_Powershell_Azure Pipelines_Azure Pipelines Tasks - Fatal编程技术网

Azure管道崩溃了在本地正常运行的pwsh脚本

Azure管道崩溃了在本地正常运行的pwsh脚本,azure,docker,powershell,azure-pipelines,azure-pipelines-tasks,Azure,Docker,Powershell,Azure Pipelines,Azure Pipelines Tasks,我到处找了,但找不到解决问题的办法 我正在尝试使用Azue管道创建CI管道,用于构建、测试和推送docker图像。构建和推送部分可以很好地处理Azure任务 我一直在运行Powershell脚本以获取docker日志。(为了使其更具可读性,省略了变量声明。我知道它们可以工作,因为docker容器检查命令在脚本中没有问题。) 这是脚本的基本部分。在我本地的Powershell 7终端中运行此功能非常有效,我可以获得指定的所有日志输出 但是,当启动管道时,会出现以下错误: __________ LO

我到处找了,但找不到解决问题的办法

我正在尝试使用Azue管道创建CI管道,用于构建、测试和推送docker图像。构建和推送部分可以很好地处理Azure任务

我一直在运行Powershell脚本以获取docker日志。(为了使其更具可读性,省略了变量声明。我知道它们可以工作,因为docker容器检查命令在脚本中没有问题。)

这是脚本的基本部分。在我本地的Powershell 7终端中运行此功能非常有效,我可以获得指定的所有日志输出

但是,当启动管道时,会出现以下错误:

__________ LOGS FOR rabbitmq __________
Configuring logger redirection
##[error]PowerShell exited with code '1'.
如果我查看本地启动脚本的docker日志,我会发现“配置记录器重定向”对应于应该打印的第一行,因为错误会在两行之后出现(因为它应该基于-Context标志)。然而,我不明白错误是从哪里来的。请注意,该错误对应于管道语法“##vso[task.LogIssue type=error;]”,该语法未在此行的脚本中使用

让事情变得更有趣:我正在本地机器上运行一个自托管的Windows代理。因此,本地脚本和Azure代理管道访问完全相同的Powershell

到目前为止,我发现:docker日志将输出打印到stdout和stderr,由于stderr中有许多感兴趣的内容,我必须重定向它,因此我使用2>&1。但是,在使用此重定向时,我遇到了一个问题,即Powershell使用对象而不是字符串,因此|%{“$”}。每次我手动运行脚本时,这些解决方案都可以正常工作,但每次管道运行脚本时都会失败

docker-compose --file="$ComposeFilePath" `
               --project-name="$ComposeProjectName" `
               up --detach    
Start-Sleep -s 10
foreach ($ComposeService in $ComposeServices)
    {
        Write-Output "__________ LOGS FOR $($ComposeService.ServiceName) __________"
        $InfoMessage = docker logs "$($ComposeService.ContainerId)" 2>&1 | %{ "$_" }`
                                | Select-String -Pattern "error" -Context 2,2
        Write-Output $InfoMessage 
    
        $InfoMessage = docker logs "$($ComposeService.ContainerId)" 2>&1 | %{ "$_" }`
                            | Select-String -Pattern "Traceback" -CaseSensitive -Context 5,40
        Write-Output $InfoMessage 
    }
为了确保Azure管道任务的完整性:

    - task: PowerShell@2
      inputs:
       pwsh: true
       targetType: 'filePath'        
       filePath: '$(Build.SourcesDirectory)/docker_compose_error_checks.ps1'
我感谢你的帮助。最坏的情况下,我会切换到bash,并在那里试试运气

致意