首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尽管构建失败,Azure DevOps Docker@2任务通过

尽管构建失败,Azure DevOps Docker@2任务通过
EN

Stack Overflow用户
提问于 2022-11-17 16:11:05
回答 1查看 30关注 0票数 0

我正在构建一个管道在Azure DevOps,并试图创建一个职务,以建立一个码头形象。我的意图是,如果Docker构建失败,该步骤将失败,但与我的预期相反,即使构建有错误,任务仍然会通过。

这是我的管道的一部分:

代码语言:javascript
复制
stages:
- stage: build
  displayName: Build
  jobs:
    - job: build_service
      displayName: Build Service
      dependsOn: []
      pool:
        vmImage: 'ubuntu-22.04'
      steps:
        - task: Docker@2
          displayName: Docker Build
          inputs:
            command: build
            addBaseImageData: false
            addPipelineData: false
            buildContext: .
            Dockerfile: $(Build.SourcesDirectory)/servic/Dockerfile

由于$(Build.SourcesDirectory)/servic/Dockerfile中的错误,所以找不到Dockerfile。构建失败,但管道任务仍然成功。以下是日志:

代码语言:javascript
复制
(node:2524) UnhandledPromiseRejectionWarning: Error: No Dockerfile matching  /home/vsts/work/1/s/servic/Dockerfile  was found.
    at Object.run (/home/vsts/work/_tasks/Docker_e28912f1-0114-4464-802a-a3a35437fd16/2.212.1/dockerbuild.js:15:15)
    at getToken.then (/home/vsts/work/_tasks/Docker_e28912f1-0114-4464-802a-a3a35437fd16/2.212.1/docker.js:72:27)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:2524) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2524) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Finishing: Docker Build

对我来说,它看起来像是Docker@2任务中的一个bug,但仍然不知道我是否缺少一些设置。

EN

回答 1

Stack Overflow用户

发布于 2022-11-18 06:15:22

我可以复制你的问题。然后,如果您在本地运行相同的命令,您可能会遇到相同的错误“无法找到dockerfile”。在这里,Docker@2任务只键入执行命令“docker构建-file*”时获得的错误,而不将其识别为任务的标准错误。这应该是任务运行良好的原因。

我的建议是直接运行命令,使用命令行任务,如Bash@3任务。应该是这样的:

代码语言:javascript
复制
- task: Bash@3
  inputs:
    targetType: 'inline'
    failOnStderr: true    #for the task has the parameter 'fail the task when there are standard error print, you could add it for a try'
    script: 'docker build --file ***'

如果任务上有一些错误,它就会失败。希望能帮上忙。非常感谢。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74478691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档