0
votes

I'm working on a declarative Jenkins pipeline script to build and publish the artifact to JFrog Artifactory.
We have only one project repository and the services are under services folder. All the services have its own pom.xml .We need to write a script to pipeline script to build and publish the artifact to JFrog only when there is a change detected in the individual directory structure of services.
As per client , we cannot have individual repository for each services. The issue here, with the below script(using rtUpload) I'm unable to publish the artifacts as maven artifact( group id, artifact id and version number) to artifactory. Requesting your help on this.

The project structure is given below.

trinad(repository)
|
|-----/java/services/customer_quote/pom.xml
|
|-----/java/services/customer_rate/pom.xml
|
|-----/java/services/customer_renew/pom.xml

pipeline{
   agent any
   tools{
       jdk 'JDK'
       maven 'Maven'
   }
   stages{
     stage('Build'){
        when {
          anyOf{
                changeset '**/services/customer_quote/**'
          }
        }
        steps{
         sh 'mvn -v'
         sh 'mvn -f java/services/customer_quote/pom.xml' clean install
        }
        when {
          anyOf{
                changeset '**/services/customer_rate/**'
          }
        }
        steps{
         sh 'mvn -v'
         sh 'mvn -f java/services/customer_rate/pom.xml' clean install
        }
   
     }
     stage('publish'){
      when {
          anyOf{
                changeset '**/services/customer_quote/**'
          }
        }
        steps{
            rtUpload{
              serverId:'Artifactory',
              spec:'''{
               "files":[
                {
                    "pattern":"/services/customer_quote/target/customer-quote-*.jar",
                    "target": "trinad"/${BUILD_NUMBER}/"    
                }]
              }
            }
        
        }
        //publish steps for other services goes here
     } 
   }
}
1
Do you try to use maven deploy instead of rtUpload ? - fmdaboville

1 Answers

0
votes

I would recommend using the Maven-based jobs as mentioned in the wiki and test it out. As you are trying to build using the "mvn" client and deploying to Artifactory using rtUpload, I doubt if this is being picked up correct or not. You either try out with mvn deploy first or have your pipeline setup with the one which is mentioned in the wiki above.

A sample JenkinsFile for the declarative script can be found under this JFrog's Github. Probably using the rtMavenRun should be helpful in building and deploying the file.