2

our jenkins job failes to parse poms, as it cannot find the parent pom. (Jenkins version 2.332.3)

Parsing POMs
Failed to transfer Could not find artifact <our parent pom> in central (https://repo.maven.apache.org/maven2)
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for <current project>: Could not find artifact <our parent pom> in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 10, column 13

The project is set up as a maven project and the no goal can be executed. If I configure the job as a pre-built step, the maven build is successfull.

Flags like -U and -X do not change the log message.

The parent pom is located in an artifact in our private nexus repository and should already be in the local .m2 repository, as the pre build step is successfull.

On the old jenkins (2.263.4) server, the build works just fine.

Any hint will be highly appreciated

Felix
  • 123
  • 2
  • 12
  • Can you show us the pipeline code which is not working? – ycr Jun 13 '22 at 10:46
  • Based on this: `https://repo.maven.apache.org/maven2` it looks like your configuration in Jenkins does handle the `settings.xml` correctly because you are accessing central repository within a corporate environment. Jenkins should provide a `settings.xml` which contains correct configuration to access only the internal repository manager (nexus) and never access outside... Usually you should do that via the config file provider plugin in Jenkins which handles that... – khmarbaise Jun 13 '22 at 10:50
  • Try wiping your local repo and rebuilding. I bet it will fail, same as Jenkins. Also paste at least first dozen lines of pom.xml. and using job type maven is not recommended; pipeline, or freestyle (w/maven step(s)) instead. – Ian W Jun 13 '22 at 11:02
  • @khmarbaise: wel another job on the same jenkins is working perfectly fine, so the connection between jenkins and nexus can be used. Also the pre build step would fail, if the settings.xml wouldn't be set correctly – Felix Jun 15 '22 at 08:36
  • @IanW, yes, I totally agree. Usually I build the jobs with Jenkins files. However this is a parent pom with repository specification only, so it would be some kind of overkill to build up a pipeline. Can you say, why the job type _maven_ is not recommended? – Felix Jun 15 '22 at 08:40
  • YMMV, but "maven is not recommended", as evidenced by the "Devil Jenkins image](https://plugins.jenkins.io/maven-plugin/) is because the devil is in the details (see plugin notes). It used to be [integrated w/Jenkins core](https://www.jenkins.io/doc/upgrade-guide/2.204/#stop-bundling-maven-plugin-and-subversion-plugin-with-jenkins), then separate but bundled, but that tight integration lead to Jenkins doing things you are not aware of (eg: automatically reconfigure your build to use the JDK). – Ian W Jun 15 '22 at 09:07
  • Most of the "advanced integration" should really be defined in your pom anyway so it behaves the same in and out of Jenkins. Even the "chaining of dependency builds: is better handles using an artifact repository manager. Also, it's designed only run a single maven build step, which is generally not how people use Jenkins anymore. – Ian W Jun 15 '22 at 09:07
  • I should add that even the plugin itself comes with [its own warning](https://github.com/jenkinsci/maven-plugin/blob/36265f750bfd7dbe8cdb4e2910088a6d3b849b04/pom.xml#L42): `This plug-in provides, for better and for worse, a deep integration of Jenkins and Maven: Automatic triggers between projects depending on SNAPSHOTs, automated configuration of various Jenkins publishers (Junit, ...).` – Ian W Jun 15 '22 at 09:38

2 Answers2

3

I was facing this issue after upgrading from Jenkins "1.651.3" to "2.346.3 LTS".
When I created a bright new job (without copy) - it worked.
When I run the upgraded job - it failed.

Our Maven settings.xml looked like this:

<settings   ... >
    <mirrors>
        <mirror>
            <id>my-mirror-id</id>
            <name>Name for my mirror</name>
            <url>http://myrepo.com/my-release-artifacts/</url>
            <mirrorOf>external:*,!my-snapshots-artifacts</mirrorOf>
        </mirror>
    </mirrors>
    ...
</settings>

Maven works with this configuration, but Jenkins was not able to parse this pom correctly and didn't use the mirror to download the parent pom.

So yes Jenkins is not able to build this correct maven project.

Right now I fixed it for us by specifying this repository explicitly in the profile. So Jenkins is able to parse the repository - like this:

<settings   ... >

    <mirrors>
        <mirror>
            <id>my-mirror-id</id>
            <name>Name for my mirror</name>
            <url>http://myrepo.com/my-release-artifacts/</url>
            <mirrorOf>external:*,!my-snapshots-artifacts</mirrorOf>
        </mirror>
    </mirrors>

    ...

    <profiles>
        ...

      <profile>
         <id>release-repo</id>
         <repositories>
             <repository>
                 <id>my-release-artifacts</id>
                 <url>http://myrepo.com/my-release-artifacts/</url>
                 <releases>
                     <enabled>true</enabled>
                 </releases>
                 <snapshots>
                     <enabled>false</enabled>
                     <updatePolicy>always</updatePolicy>
                 </snapshots>
             </repository>
         </repositories>
         <activation>
             <activeByDefault>true</activeByDefault>
         </activation>
      </profile>

    </profiles>

    ...
</settings>

It took me a few days to find this problem in the upgrade. Good luck with that everyone.

bugs_
  • 3,544
  • 4
  • 34
  • 39
1

Specifying the path to the explicit settings.xml helped this time.

  • Yes, it is using the settings from root, which is most likely not recommended
  • The Jenkins instance is running in an docker container, which is based on an own image, that has the official jenkins image as its root.
  • Still it is weird, as another job works fine without specifying this path

enter image description here

Felix
  • 123
  • 2
  • 12