Uploaded image for project: 'Jenkins Artifactory Plug-in'
  1. Jenkins Artifactory Plug-in
  2. HAP-1234

When calling the Maven versions plugin through Artifactory, default repo is used

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: 4 - Normal
    • Resolution: Unresolved
    • Affects Version/s: 2.16.2
    • Fix Version/s: None
    • Component/s: Maven3
    • Labels:
      None
    • Environment:

      Cloudbees Jenkins 2.129.4.3-rolling

      Maven 3.5.3 running in Docker container,

      Container OS: CentOS 7.5.1804,

      JDK: Oracle JDK 1.8.0_191

      Description

      Problem

      When calling the Maven versions plugin via Artifactory, the plugin doesn't use the resolver configured in the mavenBuild object.

      Steps to reproduce

      You need to have configured a Artifactory server on Jenkins - we will label it "AF-SERVER" in the pseudo-pipeline code here.

      Maven is declared in the Jenkins tools under label MAVEN-353

      stage('Check versions') {
          steps {
              script {
                  def afServer = 
                  def builder = Artifactory.newMavenBuild()
                  builder.resolver server: afServer, releaseRepo: 'myrepo-maven', snapshotRepo: 'myRepo-maven'
                  builder.deployer server: afServer, releaseRepo: 'myrepo-maven', snapshotRepo: 'myRepo-maven'
                  builder.deployer.deployArtifacts = false
                  builder.tool = 'MAVEN-353'
                  builder.run pom: 'pom.xml', goals: "versions:update-parent versions:use-releases -DparentVersion=${parentToUse}"
              }
          }
      }
      

      Actual Result

      The result of the above script is that, during the Maven build, the dependencies and plugins are fetched from the Artifactory repo.

      However, when it comes to checking the version of the parent, Maven will search for it on the Maven central repo, based on the local Maven "settings.xml" file.

      Expected Result

      One would expect that the "versions" plugin uses the repository defined as the "resolver".

      Workaround

      If it is not possible to change the settings.xml defined on the build agent, a possible workaround is to define a "settings.xml" referencing the Artifactory server in the Jenkins configuration files, using the Config Files provider plugin, and use the configured Maven tool directly (i.e. not through a MavenBuild object), referencing this settings file.

      The pseudo code would look like:

      stage('Check versions') {
          steps {
              script {
                  withMaven(
                      maven: 'MAVEN-353',
                      mavenSettingsConfig: 'MAVEN-SETTINGS') {
                      sh "mvn versions:update-parent versions:use-releases -DparentVersion=${parentToUse}"
                  }
              }
          }
      }

        Attachments

          Activity

            People

            Assignee:
            eyalb Eyal Ben Moshe
            Reporter:
            anagrys Vincent Klock
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: