2017-07-15 31 views
1

我使用artifactory的插件在Jenkinsfile开我的Maven构建:如何使用artifactory插件指定maven本地存储库路径?

def goals = "clean install" 
def artifactory = Artifactory.server 'artifactory' 

configFileProvider([configFile(fileId: 'simple-maven-settings', variable: 'MAVEN_USER_SETTINGS')]) { 
    def mavenRuntime = Artifactory.newMavenBuild() 
    mavenRuntime.tool = 'maven350' 
    mavenRuntime.resolver server: artifactory, releaseRepo: '…', snapshotRepo: '…' 
    mavenRuntime.deployer server: artifactory, releaseRepo: '…', snapshotRepo: '…' 

    def buildInfo = mavenRuntime.run pom: 'pom.xml', goals: "-B -s ${MAVEN_USER_SETTINGS} ${goals}".toString() 

这工作得很好,但Maven使用默认的共享位置〜/ .m2目录/库

我想重现在转移到管道并为每个作业分配自己的本地存储库之前的行为。

我没有找到任何设置... 我该如何继续?

回答

2

默认情况下,maven使用用户主目录下.m2目录下的本地maven存储库。 如果你想Maven来创建本地存储库,例如,在你的工作的工作空间,添加-Dmaven.repo.local = .m2目录系统属性的目标值,如下所示:

def buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -Dmaven.repo.local=.m2' 

-Dmaven.repo.local的值指向用于这个maven构建的本地maven仓库。 你可以阅读更多关于它here`

2

你可以做这样一个Jenkins Pipeline with Maven

withMaven(
     // Maven installation declared in the Jenkins "Global Tool Configuration" 
     maven: 'M3', 
     // Maven settings.xml file defined with the Jenkins Config File Provider Plugin 
     // Maven settings and global settings can also be defined in Jenkins Global Tools Configuration 
     mavenSettingsConfig: 'my-maven-settings', 
     mavenLocalRepo: '.repository') { 

     // Run the maven build 
     sh "mvn clean install" 

    } // withMaven 

在那里,你可以简单地定义本地缓存的位置。

相关问题