0
votes

I have a script in Java, I could run it with maven commands locally and even in the local Jenkins setup (localhost)

Same set of scripts when I try to run from company jenkins server, it throws an error as this :

  • [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: unknown error: Unknown host repo.maven.apache.org: unknown error -> [Help 1] [ERROR]*

Note : I setup the jenkins server from ansible playbook, and the pipeline script is as follows:

    node {
  def mvnHome
  stage('Preparation') { // for display purposes
     // Get some code from a GitHub repository
     git branch: '*/work', credentialsId: 'git-deploy', url:'<correct git url>'
  }
  stage('Build') {
     // Run the maven build
        docker.image("maven:3.2-jdk-8").inside("--privileged=true -e TZ=Asia/Singapore") {
           sh 'mvn --version'
           sh 'which mvn'
           sh "'/usr/bin/mvn' clean test"
        }

  }

What could be the cause? please help.

1
'Unknown host' error indicates there may be an issue with DNS. What do you see when you curl the repo endpoint? - noelob
Hi, this is what I see when curl : <html> <head><title>302 Moved Temporarily</title></head> <body> <h1>302 Moved Temporarily</h1> <ul> <li>Code: Found</li> <li>Message: Resource Found</li> <li>RequestId: 962A7C8D93DFC4FF</li> <li>HostId: azwOUarJzTv13ic/1nehAgQVba2RU06i2QopsL/hpwuftTRRGBZp9lW98YDxXz7f5XozIvN+7tA=</li> </ul> <hr/> </body> </html> - AJ ano
Try curl -L https://repo.maven.apache.org/maven2 to follow the redirect. As @anil mentions in his answer, there's possibly a proxy between your server and Maven central that is causing the issue. - noelob

1 Answers

0
votes

It looks like a proxy issue.

Your Maven setup is unable to download the maven-clean-plugin-2.5.jar.

Try to download the jar file manually in the machine where Jenkins is installed. Open the following link in the browser:

http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar

If you are able to download it here, then check your browser's proxy and try to use the same proxy in the settings.xml of your maven.

Example:

<proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
</proxy>

Check this guide for proxy settings in Maven.