【问题标题】:How to publish to Nexus the artifact generated by a Gradle project in Jenkins如何将 Jenkins 中 Gradle 项目生成的工件发布到 Nexus
【发布时间】:2018-05-28 07:47:54
【问题描述】:

我有一个带有以下 uploadArchives 配置的 Gradle 项目,用于将其工件发布到 Nexus:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: 'http://releasesrepo')
            snapshotRepository(url: 'http://snapshotsrepo')
        }
    }
}

如您所见,此配置中没有凭据。

这个构建将作为一个 Freestyle 项目从 Jenkins 运行,所以我只需要在 Build - Invoke Gradle Script - Tasks -> build upload

中指定

从 Jenkins 配置 Nexus 凭据并将其传递给 Gradle taks 的正确方法是什么(我不希望它们在带有源代码的 Git 存储库中)?

【问题讨论】:

    标签: maven jenkins gradle nexus


    【解决方案1】:

    有三种不同的方式:

    1.使用环境变量

    def nexusUser = hasProperty('nexusUsername') ? nexusUsername : System.getenv('nexusUsername')
    def nexusPassword = hasProperty('nexusPassword') ? nexusPassword : System.getenv('nexusPassword')
    def nexusReleaseUrl = hasProperty('nexusReleaseUrl') ? nexusReleaseUrl : System.getenv('nexusReleaseUrl')
    def nexusSnapshotUrl = hasProperty('nexusSnapshotUrl') ? nexusSnapshotUrl : System.getenv('nexusSnapshotUrl')
    
    repositories {
        mavenDeployer {
            repository(url: nexusReleaseUrl) {
                authentication(userName: nexusUser, password: nexusPassword);
            }
            snapshotRepository(url: nexusSnapshotUrl) {
                authentication(userName: nexusUser, password: nexusPassword);
            }
        }
    

    }

    2.使用~/.gradle/gradle.properties(记得是用户jenkins下)

    nexusUser=user
    nexusPass=password
    
    uploadArchives {
      def nexusUser = "${nexusUsername}"
      def nexusPassword = "${nexusPassword}"
    
      repositories {
        mavenDeployer {
            repository(url: 'your nexus releases') {
                authentication(userName: nexusUser, password: nexusPassword);
            }
            snapshotRepository(url: 'your nexus snapshot') {
                authentication(userName: nexusUser, password: nexusPassword);
            }
        }
      }
    }
    

    3.使用全局凭证

    你有一个例子here(这是给特拉维斯的)如果你想看看

    【讨论】:

      猜你喜欢
      • 2014-05-19
      • 2019-02-02
      • 2016-01-13
      • 2023-01-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 2013-12-06
      • 2013-07-05
      相关资源
      最近更新 更多