1

I have close to 60 artifacts(jar) created from a project I want to upload it to nexus ,I have tried diff wildcards it failed.

can I create a loop or is there a beter way to do this .

below is snippet from my jenkins file


nexusArtifactUploader artifacts: [
            [artifactId: "test-services", classifier: '', file: "/server/services/deploy/*.jar', type: 'jar']
          ],
          credentialsId:  NEXUS_CREDENTIAL_ID,
          groupId: "$group",
          nexusUrl: NEXUS_URL,
          nexusVersion: 'nexus3',
          protocol: 'https',
          repository: NEXUS_REPO ,
          version: "$nexus_version${BUILD_NUMBER}-SNAPSHOT"
            }
        }
Mano
  • 51
  • 1
  • 10
  • 1
    If you use apache maven, make use of [maven deploy plugins](https://maven.apache.org/plugins/maven-deploy-plugin/). You need to create settings.xml file on this ~/.m2/settings.xml path. [reference of setting.xml file](https://maven.apache.org/settings.html) file with nexus details, then after a build use `mvn deploy:deploy` maven goal to push the artifact to Nexus. – Samit Kumar Patel Dec 06 '20 at 14:19

1 Answers1

2

I added a for loop and let uploader iterate over the artifacts. Im not sure if its the right approach .but it does the job as of now . still looking for better options

let me know if i can improve the below.

def  FILES_LIST = sh (script: """ls   'server/services/deploy/' """,returnStdout: true).trim()
             //DEBUG
             echo "FILES_LIST : ${FILES_LIST}"
             //PARSING
            for(String ele : FILES_LIST.split("\\r?\\n")){ 
            nexusArtifactUploader artifacts: [
            [artifactId: "$ele", classifier: '', file: "server/services/deploy/$ele", type: 'jar']
          ],
          credentialsId:  NEXUS_CREDENTIAL_ID,
          groupId: "com.devops",
          nexusUrl: NEXUS_URL,
          nexusVersion: 'nexus3',
          protocol: 'https',
          repository: NEXUS_REPO ,
          version: "1.0.0-${BUILD_NUMBER}-SNAPSHOT"
Mano
  • 51
  • 1
  • 10
  • I do need this too, have you found a better option? – tuxillo Mar 15 '22 at 17:52
  • 1
    Our build tool was gradle and The better option for us was to publish with gradle which is easier . [gadle publish](https://docs.gradle.org/current/userguide/publishing_maven.html) – Mano Mar 16 '22 at 05:36
  • Ok thanks. I have to upload RPMs and I'm looking for a way of doing it. I'll see if I can do it with a loop like you tried before. – tuxillo Mar 16 '22 at 10:00