Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail build upon error with push operation #1183

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

MarkRx
Copy link
Contributor

@MarkRx MarkRx commented Jul 11, 2023

Fixes DockerPushImage task not failing when pushing fails

closes #1178


class DockerPushImageFunctionalTest extends AbstractGroovyDslFunctionalTest {

def "fails on push error"() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a task for add a task for removing the container image after the push. You will also need to add a pull task to ensure that the container image is available before use. It's possible that your test case runs first and the image may not exist yet.

task removeImage(type: DockerRemoveImage) {
     dependsOn buildImage
     mustRunAfter pushImage, pullImage
     targetImageId buildImage.getImageId()
     force = true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

BuildResult result = build('pushImage')

then:
def e = thrown(Exception)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for DockerClientException here. That's the one your are throwing from the callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API doesn't seem to provide access to that information. I updated this to follow other examples

super.throwFirstError();

if (latestItem == null) {
throw new DockerClientException("Could not push image");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to get the root cause of this failure e.g. one that indicates that incorrect credentials were used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

@bmuschko bmuschko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for changes. They'll go out with the next release of the plugin.

@bmuschko bmuschko added this to the v9.3.2 milestone Jul 21, 2023
@bmuschko bmuschko merged commit a5aa395 into bmuschko:master Jul 21, 2023
@bmuschko bmuschko added bug and removed enhancement labels Jul 21, 2023
@bmuschko bmuschko changed the title Fix docker push errors not failing build Failing build upon error with push operation Jul 31, 2023
@bmuschko bmuschko changed the title Failing build upon error with push operation Fail build upon error with push operation Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DockerPushImage does not fail the task / build if the upload fails
2 participants