【问题标题】:How to move artifacts between two nexus repositories (jenkins)?如何在两个 nexus 存储库(jenkins)之间移动工件?
【发布时间】:2016-06-25 11:29:14
【问题描述】:

我们使用 Jenkins + Gradle 脚本构建。 要将工件上传到 nexus,我们使用:

uploadArchives {
        repositories {
            mavenDeployer {
                def auth = { authentication(userName: nexusUsername, password: nexusPassword) }
                repository(url: rpmReleasesRepoUrl, auth)
                pom.groupId = project.group
                pom.version = project.version
                pom.artifactId = project.product
            }
        }
    }

我们需要一份工作,从一个联结中获取工件并将其上传到另一个联结。

您能否建议更好的方法以及是否有任何有用的文章/示例(第一次看到 gradle/maven/nexus)?

【问题讨论】:

    标签: maven jenkins gradle nexus


    【解决方案1】:

    1。 Jenkins神器推广插件

    这是一个非 gradle 解决方案,但您可以在 jenkins 工作流程中使用 this jenkins plugin 将构建二进制文件从一个 nexus 存储库提升到另一个。

    2。使用命令行参数提供用于发布的 repo URL

    uploadArchives {
        ...
                repository(url: project.getProperty('repoURL'), auth)
        ...
    }
    

    然后根据需要使用不同的链接 URL 运行 gradle uploadArchives -PrepoURL=http://nexusurl

    3。使用不同的任务发布到每个 repo

    ext.repoURL=''
    
    task publishToRepo1()<<{
        repoURL = 'http://nexus1.url'
        configureRepo(repoURL)
    }
    publishToRepo1.finalizedBy('uploadArchives')
    
    task publishToRepo2()<<{
        repoURL = 'http://nexus2.url'
        configureRepo(repoURL)
    }
    publishToRepo2.finalizedBy('uploadArchives')
    
    def configureRepo(url){
        uploadArchives.repositories {
            mavenDeployer {
                def auth = { authentication(userName: nexusUsername, password: nexusPassword) }
                repository(url: url, auth)
                pom.groupId = project.group
                pom.version = project.version
                pom.artifactId = project.name
            }
        }
    }
    
    uploadArchives {
        doFirst{
            if (!repoURL){
                println "Please use publishToRepo1 or publishToRepo1 to publish"
                throw new GradleException('use of uploadArchives is restricted!')
            }
        }
    }
    

    如果直接使用消息调用 uploadArchives 以使用 publishToRepo1 或 publishToRepo2,这将导致 gradle 构建失败。直接调用这些任务将调用配置了适当的 repo url 的 uploadArchives。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      相关资源
      最近更新 更多