Jenkins Artifactory Plugin

5/14/2018

Can Jenkins Artifactory plugin run docker-in-docker? I would like to use this plugin in tandem with Jenkins Kubernetes plugin in a pipeline build provided below.

The example pipeline creates a Pod which firstly uses a git container to clone the given project-examples repository and then uses a maven container to build the project.

I suspect I am hitting this issue and just wanted to double check if it is still the case. When executed, the Artifactory plugin searches for resources, e.g. MAVEN_HOME, in the Pod instead of the maven container. Not being able to find the resources the plugin fails.

def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(label: label, containers: [
  containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
  containerTemplate(name: 'git', image: 'alpine/git', command: 'cat', ttyEnabled: true)
]) {
  node(label) {

container('maven') {
    def server
    def buildInfo
    def rtMaven


    stage ('Clone') {
        git url: 'https://github.com/jfrogdev/project-examples.git'
    }

    stage ('Test a Maven project') {           
            server = Artifactory.server 'private-artifactory'
            rtMaven = Artifactory.newMavenBuild()
            rtMaven.tool = 'maven'
            rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean build', buildInfo: buildInfo
            buildInfo = Artifactory.newBuildInfo()
    }
}
-- Gin
artifactory
docker
jenkins
kubernetes

1 Answer

7/2/2018

I've had the same problem and been trying various variations on configuring the connection to the maven installation.

The final configuration that seems to be working in picking up the maven installation that I have in my docker image is as follows:

stage("build") {
   def server=Artifactory.server('My art')
   def rtMaven=Artifactory.newMavenBuild()
   rtMaven.resolver server: server, releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot'
   rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local'
   env.MAVEN_HOME="/usr/share/maven"
   def buildInfo = rtMaven.run pom: 'sub-dir/pom.xml', goals: 'clean install'
   server.publishBuildInfo buildInfo         
}

Using env.MAVEN_HOME instead of relying on a tool configuration seems to work. Rembember to place it before rtMave.run.

-- tlund56
Source: StackOverflow