简体   繁体   中英

Jenkinsfile maven plugin inside a docker container

I'm using Jenkins with a Jenkinsfile that runs my builds inside a docker container. I have a simple Java application that I'd like to build and deploy to artifactory using the Jenkins Artifactory plugin.

My Jenkinsfile is below -

node {
  def server = Artifactory.server "my-artifactory"
  def rtMaven = Artifactory.newMavenBuild()

  stage("Prepare environment"){
    docker.image('driv/docker-maven-java-oracle').inside {

      checkout scm

      stage("Artifactory configuration") {
        rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo:'libs-snapshot-local', server: server
        rtMaven.resolver releaseRepo:'libs-release', snapshotRepo:'libs-snapshot', server: server
      }

      stage("Maven build") {
        def buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install'
      }
    }
  }
}

However, when I run builds with the above Jenkinsfile I get the error -

java.lang.RuntimeException: Couldn't find maven installation

I know that I can add a line to my Jenkinsfile like this -

rtMaven.tool = MAVEN_TOOL

...that I can use to specify a pre-configured Jenkins Tool to point the Artifactory plugin at Maven. However, it seems to me that such a pre-configured tool would have to be on the Jenkins machine, or a build node, and not inside my docker container.

So, is it possible to point the Artifactory plugin at a maven installation inside my docker container?

Thanks.

This should probably be fixed in their jenkins plugin itself but as "Christopher Orr" suggested mapping environment vars at the pipeline stage level to the same ones set in the container work

For example

stage('mystage') {
    environment {
        // If your using the official maven image, these are probably where it puts it
        MAVEN_HOME = '/usr/share/maven'
        JAVA_HOME= '/usr/local/openjdk-8'
    }
    steps {
        sh """
            # confirm location of MAVEN_HOME and JAVA_HOME in container and set in environment directive
            printenv 
        """
        ...
        // call rtMavenRun()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM