7

I am trying to upload the artifact to Nexus repository using the Artifact deployment stage in the Jenkins pipeline. For doing this I am providing Jenkins with the Nexus credentials and the path to find the repository. But, this stage is failed with an error "the connection is refused to nexus".

However, I am able to access Nexus on http://localhost:8081/nexus.

Below is the code used in pipeline_config.yml file.

artifactDeployment:
    nexus:
      version: nexus2
      url: 'http://localhost:8081/nexus/'
      repository: myrepo
      credentialsId: 'nexus'
      additionalClassifiers:
        - type: jar
          classifier: classes

screenshot

Could someone please suggest in resolving this issue?

JonathanDavidArndt
  • 2,518
  • 13
  • 37
  • 49
Sankeerth
  • 249
  • 3
  • 12

3 Answers3

2

On your VM, login to your Jenkins container

ex

docker exec -it s4sdk-jenkins-master bash

Then execute curl command to reach the nexus from there.

ex

curl http://<your VM's IP>:8081/nexus

You will be able to upload artifact to nexus, only if the host is reachable from within the Jenkins container.

Ram
  • 1,154
  • 6
  • 22
  • Thank you for the reply. i executed the commands as you mentioned, it seems like host is not reachable from Jenkins. I see the error as **Failed to connect to localhost port 8081: Connection refused** Can you please help how to resolve this? – Sankeerth Mar 15 '18 at 17:55
  • When i execute 'curl http://sankeerth-virtualbox:8081/nexus ' i see the error as **Could not resolve host: sankeerth-virtualbox ** – Sankeerth Mar 15 '18 at 17:58
  • 1
    Use IP address of your VM instead of localhost. – Ram Mar 15 '18 at 18:21
0

this looks very much like an issue with the localhost URL. From within the Jenkins container, localhost refers to that container, and not to your local Nexus.

The solution should be to use the hostname of the Nexus in your pipeline config. It looks like this is the hostname of your laptop in this case.

Hope this helps.

Best regards, Florian

Florian Wilhelm
  • 600
  • 4
  • 17
  • Thank you for your reply. I found the hostname as "sankeerth-VirtualBox". so, I replaced localhost with this hostname. But, the error is still not resolved. Could you please tell if this is what you meant? Also, I am wondering if nexus has a different hostname. If yes, could you please tell how to obtain it(Nexus is installed directly on VM). – Sankeerth Mar 14 '18 at 19:43
  • I need to know more about your setup. You installed Nexus in a Linux VM, right? Does the Pipeline also run in the same VM, or in a different VM, or using Docker for Windows? For configuring VirtualBox networks, I recommend consulting the VirtualBox manual https://www.virtualbox.org/manual/ch06.html – Florian Wilhelm Mar 15 '18 at 13:46
  • Yes, That' right. I installed Nexus on Linux VM. Yes, the pipeline also runs on the same Linux VM. – Sankeerth Mar 15 '18 at 15:05
  • So you set the uri in pipeline config to `http://sankeerth-VirtualBox:8081/nexus/`, and get connection refused? Which version of Nexus are you using? I noticed your pipeline config says `nexus2`. If you're using nexus 3, this might also be an issue. – Florian Wilhelm Mar 15 '18 at 15:33
  • Yes, i set the uri to 'http://sankeerth-VirtualBox:8081/nexus/ ' and nexus2 as version. I installed Nexus 2 in VM – Sankeerth Mar 15 '18 at 17:05
0

If You have Jenkins and Nexus container, So:

  1. Change localhost: 8081 to address ip host, eg 192.168.0.3:8081

I fixed problem in my environment local.

I hope can helps!