0
votes

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

Uploading: http://localhost:8081/nexus/content/repositories/repository/releases/blt-server/0.0.1-SNAPSHOT/blt-server-0.0.1-20190906.152523-1.war

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";
                 }

             }
         }
     }
     }

 }
1
Why is your groupid "null"? Maven will.upload to coords.based on GAV. What repositories (and of what type) have you defined in Nexus?Ian W
Without having provided a sample code of what you use in your pipeline and where you have tried editing the URL, it is difficult to tell where the problem lies. The repository URL might have been specified either in your project pom.xml or in ~/.m2/settings.xml on your build agent. If your project doesn’t use a pom.xml, the repository URL could even be a part of the mvn deploy command as the option -Durl or if you use nexusArtifactUploader, it could be specified as nexusUrl. Many possibilities!Dibakar Aditya
@Dibakar Aditya Thanks for the quick look. I've uploaded my pipeline code above. please check out.nk07
@IanW Thanks for the quick check. Regarding "groupid" null i'm not sure why its showing it as "null" I verified the pom.xml in which it has like this: ``` <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> ```nk07
@nk07 Thanks for sharing additional details. This makes troubleshooting easier.Dibakar Aditya

1 Answers

1
votes

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:

  1. Upgrade the Nexus Artifact Uploader plugin to version 2.6 or higher.
  2. Replace 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.