我想从Gradle项目中构建一个jar,并将其推送到nexus存储库。作为此过程的一部分,我创建了一个Jenkins文件,并在build.gradle中添加了一个任务“发布”任务。
我的 Jenkins 文件:
pipeline {
agent any
environment {
NEXUS = credentials('nexus-user')
}
options {
ansiColor('xterm')
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '100')
}
triggers { pollSCM('H/5 * * * *') }
stages {
stage('Checkout'){
steps { checkout scm }
}
stage('Build') {
steps { sh "./gradlew assemble" }
}
stage('deploy') {
steps {
sh "gradle -Duser.home=\"$WORKSPACE\" --gradle-user-home=\"$WORKSPACE/.gradle\" -PnexusUsername=$NEXUS_USR -PnexusPassword=$NEXUS_PSW publish"
}
}
}
}
然后build.gradlepublishing {
publications{
maven(MavenPublication){
artifactId = "testApp"
from components.java
}
}
repositories {
maven {
url = "http://localhost:8081/nexus/content/repositories/${version.endsWith('-SNAPSHOT') ? "snapshots" : "releases"}"
credentials {
username = "Dont know how to pass the username here"
password = "Dont know how to pass the password here"
}
}
}
}
谁能告诉我如何从Gradle获取用户名和密码,并在此处设置将jar发布到nexus。
最佳答案
答案是:
publishing {
publications{
maven(MavenPublication){
artifactId = "testApp"
from components.java
}
}
repositories {
maven {
url = "http://localhost:8081/nexus/content/repositories/${version.endsWith('-SNAPSHOT') ? "snapshots" : "releases"}"
credentials {
username = "nexusUsername"
password = "nexusPassword"
}
}
}
}
关于gradle - 如何将jar发布到NEXUS存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64664958/