2017-07-15 96 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 

在那裏,你可以簡單地定義本地緩存的位置。

相關問題