Reputation: 161
I'm trying to upload the artifact into nexus using Jenkins pipeline, in which the overall pipeline ends at last stage. where the artifact is not get uploading into the nexus repository.
Say example: http://localhost:8081/nexus/content/repositories/releases is my existing repository and that am trying to upload the artifact into it. But when i kick off the Jenkins pipeline build am seeing the url reaches to: http://localhost:8081/nexus/content/repositories/repository/releases. I'm quite confused where the "repository" comes from into the above url.
I tried to edit the url so many times but still getting same issue
Uploading artifact blt-server.war started....
GroupId: null
ArtifactId: blt-server
Classifier:
Type: war
Version: 0.0.1-SNAPSHOT
File: blt-server.war
Repository:releases
Downloading: http://localhost:8081/nexus/content/repositories/repository/releases/maven-metadata.xml
10 % completed (5.5 MB / 55 MB).
20 % completed (11 MB / 55 MB).
30 % completed (17 MB / 55 MB).
40 % completed (22 MB / 55 MB).
50 % completed (28 MB / 55 MB).
60 % completed (33 MB / 55 MB).
70 % completed (39 MB / 55 MB).
80 % completed (44 MB / 55 MB).
90 % completed (50 MB / 55 MB).
100 % completed (55 MB / 55 MB).
Failed to deploy artifacts: Could not find artifact :blt-server:war:0.0.1-20190906.152523-1 in releases (http://localhost:8081/nexus/content/repositories/repository/releases)
Uploading file blt-server.war failed.
I expect the url should be like this: http://localhost:8081/nexus/content/repositories/releases while uploading the war file, but it's not.
Here is my pipeline script:
pipeline {
agent {
label "master"
}
tools {
maven "Maven-3.5.2"
}
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "localhost:8081/nexus/content/repositories"
NEXUS_REPOSITORIES = "releases"
NEXUS_CREDENTIAL_ID = "SonatypeREMNexus3"
CREDENTIALSID= "********confidential***"
}
stages {
stage("clone bitbucket") {
steps {
checkout(
[
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'build']
],
submoduleCfg: [],
userRemoteConfigs: [
[
credentialsId: '********confidential***',
url: 'ssh://[email protected]:7999/blt/blt-server.git'
]
]
]
)
}
}
stage('Build & Test') {
steps {
script {
withMaven(
options: [artifactsPublisher(disabled: true)],
jdk: 'JAVA-1.8.0_152',
maven: 'Maven-3.5.2') {
sh "mvn clean package -f build/pom.xml"
}
}
}
}
stage("publish to nexus") {
steps {
script {
pom = readMavenPom file: "build/pom.xml";
filesByGlob = findFiles(glob: "build/target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version: ${pom.version}"
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: pom.version,
repository: NEXUS_REPOSITORIES,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "build/pom.xml",
type: "pom"]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
}
}
}
}
Upvotes: 1
Views: 4920
Reputation: 4203
The problem lies here:
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "localhost:8081/nexus/content/repositories"
The Nexus version specified is Nexus 3 but the URL follows Nexus 2 format.
Nexus 3 uses the URL format /repository/<repo-id>/<path-of-file>
whereas, Nexus 2 uses /content/repositories/<repo-id>/<path-of-file>
.
If you are on Nexus 2, just update the version NEXUS_VERSION = "nexus2"
.
If on Nexus 3:
localhost:8081/nexus/content/repositories
with localhost:8081/nexus
or localhost:8081
, as applicable to your Nexus repository.You can also configure Nexus 3 to use legacy URL paths.
Upvotes: 1