Work with Docker Daemon Directly - Scripted Pipeline Syntax

JFrog Integrations Documentation

Content Type

The Jenkins Artifactory Plugin supports working with the docker daemon directly through its REST API. Ensure that you set up Jenkins to work with Docker and Artifactory as mentioned in the previous section.

    // Create an Artifactory server instance, as described above in this article:
    def server = Artifactory.server 'my-server-id'

    // Create an Artifactory Docker instance. The instance stores the Artifactory credentials and the Docker daemon host address.
        // If the docker daemon host is not specified, "/var/run/docker.sock" is used as a default value (the host argument should not be specified in this case).
    def rtDocker = Artifactory.docker server: server, host: "tcp://<daemon IP>:<daemon port>"

        // Jenkins spawns a new java process during this step's execution.
        // You have the option of passing any java args to this new process when creating the rtDocker instance.
        // Here's how you do this:
        // def rtDocker = Artifactory.docker server: server, javaArgs: '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005' 

        // Pull a docker image from Artifactory.
        def buildInfo = rtDocker.pull '<artifactory-docker-registry-url>/hello-world:latest', '<source-artifactory-repository>'
        // If you already have a buildInfo instance, you can pass it as an argument to the rtDocker.pull method as follows:
        // rtDocker.pull '<artifactory-docker-registry-url>/hello-world:latest', '<source-artifactory-repository>', buildInfo 
    // Attach custom properties to the published artifacts:
    rtDocker.addProperty("project-name", "docker1").addProperty("status", "stable")

    // Push a docker image to Artifactory (here we're pushing hello-world:latest). The push method also expects
    // Artifactory repository name (<target-artifactory-repository>).
    // Please make sure that <artifactoryDockerRegistry> is configured to reference the <target-artifactory-repository> Artifactory repository. In case it references a different repository, your build will fail with "Could not find manifest.json in Artifactory..." following the push.
    def buildInfo = rtDocker.push '<artifactory-docker-registry-url>/hello-world:latest', '<target-artifactory-repository>'
        // If you already have a buildInfo instance, you can pass it as an argument to the rtDocker.push method as follows:
        // rtDocker.push '<artifactory-docker-registry-url>/hello-world:latest', '<target-artifactory-repository>', buildInfo

    // Publish the build-info to Artifactory:
    server.publishBuildInfo buildInfo