gpt4 book ai didi

maven - 如何将 Jenkins Gradle项目生成的 Artifact 发布到Nexus

转载 作者:行者123 更新时间:2023-12-03 03:59:49 25 4
gpt4 key购买 nike

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

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

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

该构建将从Jenkins作为Freestyle项目运行,因此我只需要在Build-Invoke Gradle Script-Tasks-> build upload中指定即可

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

最佳答案

有三种不同的方式:

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示例(用于Travis)

关于maven - 如何将 Jenkins Gradle项目生成的 Artifact 发布到Nexus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47809660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com