Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 如何将Jenkins中Gradle项目生成的工件发布到Nexus_Maven_Jenkins_Gradle_Nexus - Fatal编程技术网

Maven 如何将Jenkins中Gradle项目生成的工件发布到Nexus

Maven 如何将Jenkins中Gradle项目生成的工件发布到Nexus,maven,jenkins,gradle,nexus,Maven,Jenkins,Gradle,Nexus,我有一个Gradle项目,具有以下uploadArchives配置,用于将其工件发布到Nexus: uploadArchives { repositories { mavenDeployer { repository(url: 'http://releasesrepo') snapshotRepository(url: 'http://snapshotsrepo') } } } 如您所见,此配置中没

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

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: 'http://releasesrepo')
            snapshotRepository(url: 'http://snapshotsrepo')
        }
    }
}
如您所见,此配置中没有凭据

这个构建将作为一个自由式项目从Jenkins运行,因此我只需在构建中指定-Invoke Gradle Script-Tasks->
build upload


从Jenkins配置Nexus凭据并将其传递给Gradle Tak的正确方法是什么(我不希望它们与源代码一起出现在Git repo中)?

有三种不同的方法:

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

3.使用全局凭据


如果您想查看Jenkins凭据存储,并在全局配置文件提供程序(init.gradle)脚本中定义它们(如果我没记错的话),您有一个示例(针对Travis)。。。
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);
        }
    }
  }
}