Search code examples
javajenkinsartifactory

Jenkins Artifactory Plugin File Specs with subprojects


I am using Jenkins with Artifactory plugin to publish artifacts.

I build application with Java and Gradle. Artifacts are located in build/libs/ folder as by convention. Publishing with specified File Specs works if I have multi module project.

root
|--proj1
|--proj2
|--...

File Specs pattern looks like (note com.rivancic is group for Artifactory repository):

"files": [
  {
    "target": "test-repo/com/rivancic/{1}/1.0.0/{2}-1.0.0{3}",
    "pattern": "/home-dir/com/rivancic/(*)/build/libs/(*)-1.0.0(*)"
  }
]

Here first wildcard is resolved to proj1 or proj2 and artifacts are uploaded to specific modules.

Problem

The problem I face is when using multi module project with nested projects.

root
|--proj1
   |--subproj11
   |--subproj12
|--proj2
|--...

Now with the same pattern for the first subproject11 first wildcard is resolved to proj1/subproj11 instead of only subproj11. This resolves to invalid artifact module name and Artifactory throws exception

java.lang.RuntimeException: java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors: 
The target deployment path 'com/rivancic/project1/subproject11/1.0.0/subproject11-1.0.0.pom' does not match the POM's expected path prefix 'com/rivancic/subproject11/1.0.0'. Please verify your POM content for correctness and make sure the source path is a valid Maven repository root path. Status code: 409

Is there a way I can define a pattern in File Specs that it will always take just the last part of path, the final subproject instead of the whole path for the above structure


Solution

  • You can use 2 different File Specs or 2 different File Spec group: One for multi modules and the other for multi projects.

    For multi projects, use the following exmple:

    "files": [
      {
        "target": "test-repo/com/rivancic/{1}/1.0.0/{2}-1.0.0{3}",
        "pattern": "/home-dir/com/rivancic/*/(*)/build/libs/(*)-1.0.0(*)"
      }
    ]
    

    Explanation - In /*/(*) part of the spec, the first asterisk is parsed as a regular wildcard, and the one surrounded by parenthesis, is used as a Placeholder.

    More information about File Specs can be found under Using File Specs.