简体   繁体   English

Docker容器内的Jenkinsfile Maven插件

[英]Jenkinsfile maven plugin inside a docker container

I'm using Jenkins with a Jenkinsfile that runs my builds inside a docker container. 我将Jenkins与Jenkinsfile一起使用,该文件在docker容器中运行我的构建。 I have a simple Java application that I'd like to build and deploy to artifactory using the Jenkins Artifactory plugin. 我有一个简单的Java应用程序,我想使用Jenkins Artifactory插件构建并将其部署到工件。

My Jenkinsfile is below - 我的Jenkinsfile在下面-

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 - 但是,当我使用上述Jenkinsfile运行构建时,出现错误-

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

I know that I can add a line to my Jenkinsfile like this - 我知道我可以像这样在我的Jenkinsfile中添加一行-

rtMaven.tool = MAVEN_TOOL

...that I can use to specify a pre-configured Jenkins Tool to point the Artifactory plugin at Maven. ...可以用来指定预先配置的Jenkins工具,将Artifactory插件指向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. 但是,在我看来,这样的预配置工具必须在Jenkins机器或构建节点上,而不是在我的docker容器内。

So, is it possible to point the Artifactory plugin at a maven installation inside my docker container? 那么,是否可以将Artifactory插件指向docker容器内的maven安装?

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 这可能应该在其jenkins插件本身中解决,但由于“ Christopher Orr”建议在管道阶段将环境变量映射到容器工作中设置的相同变量

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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