[HAP-957] Dependency info(.POM file) missing as part of the deployment Created: 17/Jul/17  Updated: 27/Dec/18

Status: Will Not Implement
Project: Jenkins Artifactory Plug-in
Component/s: None
Affects Version/s: 2.12.0
Fix Version/s: None

Type: Bug Priority: Blocker
Reporter: Raghu S Assignee: Yahav Itzhak
Resolution: Unresolved Votes: 2
Labels: None


 Description   

We have a common component(jar) used across multiple projects as a dependency, when we publish this common component, along with jar, it's not publishing pom file.
For example, I've a common-java component and publishing snapshot version. When I publish this component using Maven 'deploy' goal, it has the following two files.

com/sample/1.6-SNAPSHOT/common-java-1.6-SNAPSHOT.jar
com/sample/1.6-SNAPSHOT/common-java-1.6-SNAPSHOT.POM

However, if I publish this using Jenkins artifactory plugin using pipeline code(code given below), it has only this:

com/sample/1.6-SNAPSHOT/common-java-1.6-SNAPSHOT.jar

Can you please validate this and let me know?

pipeline {
    agent { label "maven" }
    stages {
        stage('Build & Publish') {
            steps {
                script {
						def server = Artifactory.server 'artifacts'
						def buildInfo = Artifactory.newBuildInfo()
						def rtMaven = Artifactory.newMavenBuild()
						
						rtMaven.deployer releaseRepo:'releases-local', snapshotRepo:'snapshots-local', server: server
						rtMaven.resolver releaseRepo: 'vrepo', snapshotRepo: 'vrepo', server: server
						
						rtMaven.deployer.deployArtifacts = false
						buildInfo.env.capture = true
						
						rtMaven.run pom: 'pom.xml', goals: 'clean install -DskipTests=true', buildInfo: buildInfo
						rtMaven.deployer.deployArtifacts buildInfo
						
						server.publishBuildInfo buildInfo                    
				}
            } 
        }
    }
}


 Comments   
Comment by Yahav Itzhak [ 18/Jul/17 ]

Raghu S,
Thank you for reporting this issue.
I tried to reproduce it, but it seems to be working fine for us.

I used this project. Can you please try it and let me know if this issue persists?
Also, can you please share through Github a sample project that reproduce this issue?

Comment by Raghu S [ 18/Jul/17 ]

Thanks Yahav !
I'll create some sample and share with you soon.

Some comments about your example:
Did you use pipeline to publish the jar? If yes, can you please check in the Jenkinsfile?
When you published the jar, did you see POM file along with jar and it has dependencies?

Comment by Yahav Itzhak [ 19/Jul/17 ]

Raghu S,

Yes, I used pipeline to publish the jar. You can find the Jenkins file here.
All POMs and jars were published.

Comment by Raghu S [ 19/Jul/17 ]

Thanks Yahav for posting the Jenkins file.
Your Jenkinsfile is based on Scripted pipeline syntax and it works for me as well. But it's recommended to use declarative pipeline syntax right? The same code that you shared is not working when I run via declarative pipeline syntax. Please try and let me know if you can reproduce it. Declarative example posted in the description.

Comment by Eyal Ben Moshe [ 20/Jul/17 ]

I created a Declarative Pipeline script, based on the Scripted Pipeline script Yahav created. It seems to deploy the pom files as well.
Can you try it out?

pipeline {
    agent {label 'master'}
    stages {
        stage('Build & Publish') {
            steps {
                script {
                    git url: 'https://github.com/jfrogdev/project-examples.git'
                    
                    def server = Artifactory.server 'SERVER_ID'
                    def buildInfo = Artifactory.newBuildInfo()
                    def rtMaven = Artifactory.newMavenBuild()
                    rtMaven.tool = 'Maven-3.3.9'

                    rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo:'libs-snapshot-local', server: server
                    rtMaven.resolver releaseRepo: 'jcenter', snapshotRepo: 'jcenter', server: server

                    rtMaven.deployer.deployArtifacts = false
                    buildInfo.env.capture = true

                    rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean install -DskipTests=true', buildInfo: buildInfo
                    rtMaven.deployer.deployArtifacts buildInfo

                    server.publishBuildInfo buildInfo
                                }
            }
        }
    }
}

If this script deploys the pom files for you, then there might be a difference between the the projects. Possibly inside the pom files.

Comment by Raghu S [ 20/Jul/17 ]

Thanks for the details. As I further debug, it deploys when you have a goal install something like this:

rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean install -DskipTests=true', buildInfo: buildInfo

If you define a Maven goal as package it's not publishing the pom. something like this

rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean package -DskipTests=true', buildInfo: buildInfo

Wondering, why Maven goal matters here?

Comment by Eyal Ben Moshe [ 20/Jul/17 ]

You're right. This is actually documented here:
https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins
Deployment to Artifactory is linked and triggered by maven's install goal.

Comment by Raghu S [ 21/Jul/17 ]

Thanks I get that. If it is publishing artifact during install phase, wondering, why jar get published with package goal? In my view, if this publish process is based on the maven goal, both pom and jar should follow the same. This is going to really confuse people when jar published during package phase and both jar & pom dependency published during install phase. Do you agree?

Comment by Eyal Ben Moshe [ 21/Jul/17 ]

Completely agree.
We'll investigate this to see how we can make the deployment deterministic.

Comment by Fredrik Wendt [ 24/Sep/17 ]

This is eating us badly. Do you have a suggested workaround?

Comment by Eyal Ben Moshe [ 25/Sep/17 ]

Fredrik Wendt,
Can you elaborate?
Are you using the "install" goal? If so, then what is the Issue you are facing?

Comment by SOO Kadaster [ 16/Jan/18 ]

We face exact the same issue using a gradle build.
I followed the https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins for gradle builds and the jar appears without pom.
Note that I am migrating an existing freestyle build to jenkinsfile build. The freestyle build, using the same artifactory plugin, works fine. I use the same settings in the UI of the freestyle build in the Jenkins file.
So +1 to have this fixed.
And in the mean time: is there a ‘install’ workaround like for maven also applicable for gradle builds?

Comment by Yahav Itzhak [ 30/Jan/18 ]

SOO Kadaster,
We are trying to reproduce the problem.
Can you provide us with the job logs or a simple project example?

Comment by ILGUIZ LATYPOV [ 05/Jul/18 ]

I saw this when executing a post-build action to deploy Maven artifacts with JFrog plugin after the build step involving just the "package" goal.  Changing the goal to "install" worked this around, but I wonder if the plugin could take care of running the necessary step (and only it) to get the POM files generated before expecting them in the m2 cache (I guess).

Comment by Yahav Itzhak [ 25/Dec/18 ]

Aggregating artifacts and deploying them in `install` is a legacy behavior and it's running correctly for years. Aggregating pom files in `package` goal is not trivial and it demands weeks of development and tests.

As a workaround, one can use `clean install package`. The disadvantage of this workaround is the population of the `.m2` cache.

I'm closing the issue, but please let us know if there are any difficulties with the `clean install package` approach.

Generated at Tue Sep 22 18:21:28 UTC 2020 using Jira 8.5.3#805003-sha1:b4933e02eaff29a49114274fe59e1f99d9d963d7.