microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

Docker build doesn't fail the task when docker errors from a bad filename #17164

Closed onarres closed 1 year ago

onarres commented 1 year ago

Question, Bug, or Feature?
Type: Bug

Enter Task Name: Docker@2

list here (V# not needed):
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

Environment

Issue Description

[Include task name(s), screenshots and any other relevant details] When an invalid docker name is passed to the Docker@2 for just building the image but not publishing too, we will see an error in the logs but the task does not appear to error (no stop on standard error flag available) and so the build appears as a false positive.

Example inputs:

              - task: Docker@2
                displayName: "Build Docker Image"
                condition: succeeded()
                inputs:
                  containerRegistry: "$(acrConnection)"
                  repository: "$(dockerImageName)"
                  command: "build"
                  Dockerfile: "$(dockerFilePath)"
                  buildContext: "$(System.DefaultWorkingDirectory)"

It would be better if the Task failed because the docker command failed.

Task logs

2022-11-10T11:24:19.2515785Z ##[section]Starting: Build Docker Image
2022-11-10T11:24:19.2523857Z ==============================================================================
2022-11-10T11:24:19.2524489Z Task         : Docker
2022-11-10T11:24:19.2525019Z Description  : Build or push Docker images, login or logout, start or stop containers, or run a Docker command
2022-11-10T11:24:19.2525523Z Version      : 2.212.1
2022-11-10T11:24:19.2525890Z Author       : Microsoft Corporation
2022-11-10T11:24:19.2526312Z Help         : https://aka.ms/azpipes-docker-tsg
2022-11-10T11:24:19.2526819Z ==============================================================================
2022-11-10T11:24:19.7582274Z (node:965) UnhandledPromiseRejectionWarning: Error: No Dockerfile matching  /__w/1/s/Deployment/AcrDockerFile  was found.
2022-11-10T11:24:19.7584111Z     at Object.run (/__w/_tasks/Docker_**********-0114-4464-802a-*******/2.212.1/dockerbuild.js:15:15)
2022-11-10T11:24:19.7585322Z     at getToken.then (/__w/_tasks/Docker_*******-0114-4464-802a-******/2.212.1/docker.js:72:27)
2022-11-10T11:24:19.7586165Z     at process._tickCallback (internal/process/next_tick.js:68:7)
2022-11-10T11:24:19.7586857Z     at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
2022-11-10T11:24:19.7587495Z     at startup (internal/bootstrap/node.js:283:19)
2022-11-10T11:24:19.7588119Z     at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
2022-11-10T11:24:19.7589148Z (node:965) 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)
2022-11-10T11:24:19.7591274Z (node:965) [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.
2022-11-10T11:24:19.7597403Z ##[section]Finishing: Build Docker Image
zionyx commented 1 year ago

Same issue here.

Is there a dev guide to help the community to produce fix to these bugs?

keith-bennett-airmap commented 1 year ago

My team moved a Dockerfile from where it was expected. We forgot to update the azure_pipelines.yaml file and I was surprised that CI passed without a Dockerfile. Some teams rely on CI to tell them when something broke. Telling that CI is green when it surely failed is not good.

Mushroomator commented 1 year ago

Ran into the same issue today on a Microsoft hosted agent within one of my CD pipelines which goes on to deploy the container image to Azure Container Apps.

==============================================================================
Task         : Docker
Description  : Build or push Docker images, login or logout, start or stop containers, or run a Docker command
Version      : 2.212.1
Author       : Microsoft Corporation
Help         : https://aka.ms/azpipes-docker-tsg
==============================================================================
(node:1547) UnhandledPromiseRejectionWarning: Error: No Dockerfile matching  /home/vsts/work/1/s/HMI.Tooling.FileRepository.Frontend/HMI.Tooling.FileRepository.Frontend/Dockerfile  was found.
    at Object.run (/home/vsts/work/_tasks/Docker_e28912f1-0114-4464-802a-a3a35437fd16/2.212.1/dockerbuild.js:15:15)
    at Object.run (/home/vsts/work/_tasks/Docker_e28912f1-0114-4464-802a-a3a35437fd16/2.212.1/dockerbuildandpush.js:13:31)
    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:1547) 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:1547) [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.

Because of this silent error my deployment goes ahead and I deploy a new revision to Azure Container Apps which also does not give me any error log, therefore one would assume the deployment was successful. However, the application cannot be reached and when looking in the Azure portal one can see that the container app just stays in Provisioning status forever (no errors here as well). Only when I looked into my container registry and did not find the image I was trying to push I got back to the pipeline and saw that there was indeed an error.

TL;DR

What I am trying to say, this clearly is an error which should be reported as such and cause the pipeline to fail, because in subsequent steps this might also not cause an issue and leave you with a failing deployment without you noticing.

Nevertheless, the fix is obviously quite easy. Adjust the path or if you are in a deployment job within your pipeline checkout the repo source code first which was the error in my case.

On the bright side: With a new Node version which will exit with an non-zero exit code on Promise rejection this bug will fix itself ;)

Bafff commented 1 year ago

Does anybody found a solution for this?

rubenaster commented 1 year ago

Same here. I just held a workshop for a customer regarding Docker and Azure with DevOps Pipelines and this error was only logged as a warning and didn't stop the pipeline.

A solution would be greatly appreciated.

Btw. agent is self-hosted.

jade-lucas commented 1 year ago

Having same issue with Docker@2 task. As stated, if the dotnet build fails within the Docker@2, the overall pipeline does not fail. Which for us, we build unit tests assemblies from Docker@2 task. When the builds fail in Docker@2, the unit tests are never executed and the pipeline continues. We have to put in some hacky powershell to detect when the build fails as part of the Docker@2 task. We are setting the continueOnError attribute of the Docker@2 task to false. Seems like that attribute is not properly implemented or honored in Docker@2.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Bafff commented 1 year ago

So there is no workaround?