Azure-devops-docs: Docker build with tags requires containerRegistry

Created on 18 Aug 2019  Â·  9Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

Thanks for the updating the task to version 2. Unfortunately the task input and example for each command is still not clear enough :( I tried over and over to use build and push docker image separately, the tags I put during build kept missing when pushing.

Turns out, reading from https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/DockerV2/dockerbuild.ts, it requires containerRegistry defined so tags will be added to the fully qualified image name to push. Can you please update this page as containerization in CI/CD is more common these days.

    let imageNames: string[] = [];    
    // if container registry is provided, use that
    // else, use the currently logged in registries
    if (tl.getInput("containerRegistry")) {
        let imageName = connection.getQualifiedImageName(repositoryName, true);
        if (imageName) {
            imageNames.push(imageName);
        }
    }
    else {
        imageNames = connection.getQualifiedImageNamesFromConfig(repositoryName, true);
    }
    ...
    let tags = tl.getDelimitedInput("tags", "\n");
    let tagArguments: string[] = [];
    // find all the tag arguments to be added to the command
    if (imageNames && imageNames.length > 0) {
        imageNames.forEach(imageName => {
            if (tags && tags.length > 0) {
                tags.forEach(tag => {
                    tagArguments.push(imageName + ":" + tag);
                });
            }
            else {
                // pass just the imageName and not the tag. This will tag the image with latest tag as per the default behavior of the build command.
                tagArguments.push(imageName);
            }
        });
    }
    else {
        tl.debug(tl.loc('NotAddingAnyTagsToBuild'));
    }

Thanks!


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 devops-cictech devopprod doc-bug stale-issue

Most helpful comment

Unsure about your specific reason for wanting the build and push to be separate but I was able to follow the example under 'Build and Push' to login to both my Docker Hub & Azure Container Registry and then do one 'Build and Push'. This resulted in both of my registries each getting a copy of each image/tag combo. It sounds like this might be the behavior you're looking for?

All 9 comments

Unsure about your specific reason for wanting the build and push to be separate but I was able to follow the example under 'Build and Push' to login to both my Docker Hub & Azure Container Registry and then do one 'Build and Push'. This resulted in both of my registries each getting a copy of each image/tag combo. It sounds like this might be the behavior you're looking for?

Unsure about your specific reason for wanting the build and push to be separate

My scenario is after all unit tests passed, I run the image as container then run integration tests against it.

Images only then tagged as latest and pushed to registry when integration tests passed so I am sure that when Azure Container Service spin it up there will be no issue in containerised app.

I don't want to push an untested image to registry

I am able to run docker task (Run ) in background and task completes successfully. I am looking to stop container at the end of pipeline (Docker stop .....) in another task at the end of pipeline. I do not see stop command in docker task. Any suggestion to stop containers in docker task.

I agree with this issue. Docker build and docker tag dont require credentials (dockerregistry connection) to run. Why are they a requirement? If the team only wants to run docker build, why is a service connection required?

We noticed this too, while converting to yaml pipelines. We only use this task for building the docker file and then use an AWS task to push the image to ECR.
That means we cannot tag our image with the docker task.

Workaround is to pass --tag in build arguments like this:
--tag $(ImageTag)

Another case for separating Build and Push is also simply to pass build arguments, which is clearly indicated on this documentation page.
It happens for example if you want to use --build-arg, you can't buildAndPush then.

This cost us an hour to figure out. Please update the documentation.

This issue hasn't been updated in more than 180 days, so we've closed it. If you feel the issue is still relevant and needs fixed, please reopen it and we'll take another look. We appreciate your feedback and apologize for any inconvenience.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepzgk picture sandeepzgk  Â·  3Comments

o-o00o-o picture o-o00o-o  Â·  3Comments

Naphier picture Naphier  Â·  3Comments

anlatsko picture anlatsko  Â·  3Comments

csutorasr picture csutorasr  Â·  3Comments