12
votes

I have a Jenkins job which is supposed to build a Jar and add it to Nexus. I have configured post build action to deploy maven artifact to nexus repository.

The problem is, the nexus is expecting username and password. How would i set these in the Jenkins? I do not have access to jenkins settings.xml file. I need to pass username and password in the Jenkins job itself.

3

3 Answers

4
votes

Take a look at the Config File Provider Plugin. It allows you to provide your own settings.xml for jenkins to use where you can configure all the credentials that you might need.

0
votes

Jenkins and its plugins are using your maven properties. you should provide credentials of nexus repo details in maven settings.xml as mentioned below.

<servers>
<!-- This server.id matches my nexus group -->
<server>
<id>nexus-group</id>
<username>release</username>
<password>****</password>
</server>
0
votes

The following steps are to upload an artifact from Jenkins to Nexus3 after the building process. This process worked for me and I hope you will find it useful.

  1. Add to Jenkins the nexus-artifact-uploader plugin.
  2. Create a new set of username-password credentials in Jenkins where username and passwords are the ones that you use to connect to nexus.
  3. In the Job's configure page, in the Post steps area, select as post step the Nexus artifact uploader.
    • select Nexus3 for Nexus version
    • select available protocol (the one that your nexus is using)
    • give the main url that your nexus is (without the repository/repository_name there)
    • in the credentials area give the credentials that you created in step 2
    • for groupId give: ${POM_GROUPID}
    • for version give ${POM_VERSION}
    • in the field repository give the name of your repository in nexus
  4. Then you should add the specific artifacts you want to upload by pressing add. I personally add two artifacts, the default packaging (probably jar) and a pom:
    • add an artifact with the following fields:
      • ArtifactId: ${POM_ARTIFACTID}
      • Type: ${POM_PACKAGING}
      • File: target/${POM_ARTIFACTID}-${POM_VERSION}.${POM_PACKAGING}
    • and another for pom:
      • ArtifactId: ${POM_ARTIFACTID}
      • Type: pom
      • File: pom.xml
  5. Save the configuration and return back to the jobs main page.
  6. After all these are done, give it a try by manually triggering the job.
  7. Fingers crossed you will be able to see in the build's log the uploading process.