How to bring information about a Docker image into the Artifactory build info with Gradle Jib and Artifactory plugin?

276 Views Asked by At

I want to create a Docker image with Gradle and the Jib plugin and bring it to Artifactory. The Docker image should be included in the Artifactory build info.

I can create the Docker image with the Jib Plugin. But how can I get the information about the Docker image into the Artifactory Buildinfo?

The relevant part of my gradle build file:

plugins {
    id 'java'
    id 'maven-publish'
    id "com.google.cloud.tools.jib" version "3.3.2"
    id 'com.jfrog.artifactory' version '5.1.6'
}

jib {
    from {
        image = "myRepo/$myBaseImage"       
    }
    to {
        image = "myRepo/myProject:${myTag}"
    }
}

artifactory {
    contextUrl = 'https://myRepo/artifactory/'
    publish {
        repository {
            repoKey = 'myRepo'
        }
        clientConfig.info.setBuildNumber(project.version)
        defaults {
            publications ('ALL_PUBLICATIONS')
            publishBuildInfo = true
            publishArtifacts = true
        }
    }
}
2

There are 2 best solutions below

0
Linh Vu On

By default, after running gradle jib or actually gradle jibDockerBuild, you can find the image digest and the image ID at build/jib-image.digest and build/jib-image.id respectively.


Refer: https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#outputpaths-closure

0
yahavi On

To create the Docker image and upload it to Artifactory, you can refer to the guidelines provided here: https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#using-jfrog-container-registry-jcr-or-jfrog-artifactory

Currently, the collection of build information for JIB is exclusively supported by the Jenkins Artifactory plugin. You can check out the Maven JIB example, which is applicable to Gradle as well.