0
votes

I have a Maven SpringBoot Project. I want to push it to a cloud foundry. For that I have written a groovy pipeline script for Jenkins. What I have to add? in the script and/or in the pom.xml to publish it in Artifactory so that Jenkins will pull the code from Git and publish it to Artifactory.In another enviroment I'll pull the artifactory versioned JAR and Push it to Cloud Foundry.

say my project's groupId is com.example, artifactid is XYZ and version is 1.0-SNAPSHOT.

2

2 Answers

0
votes

So just to be clear, you aren't going to publish the code to Artifactory, you're going to publish the artifacts that the Maven step in your pipeline produces. You can do this right from Maven (maven deploy or maven release:prepare release:perform) provided you have your Maven configuration setup to properly authenticate with the target Artifactory server.

You can also use the Artifactory plugin which provides steps to accomplish this:

https://jenkins.io/doc/pipeline/steps/artifactory/

Finally, you can use the Cloud Foundry plugin in another stage of your current pipeline, or in a 'deployment' pipeline to deploy the artifact(s) to your Cloud Foundry instance.

https://jenkins.io/doc/pipeline/steps/cloudfoundry/

0
votes

If you are using gitlab and talking about jenkins pipeline script , you have to create a pipeline job. below is the sample groovy script that you can enhance.

 node {

    stage ("Checkout"){
        checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: 'master']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'your_git_cred', url: 'your_gitlab_url']]]   
    }

    stage ("Build and Push to Artifactory"){
       tool name: 'Maven3.0', type: 'maven'
       sh "mvn clean deploy"
    }  
}

In the pom , you have to add the artifactory location in the distribution management

<distributionManagement>
        <repository>
            <id>artifactory</id>
            <url>your_artifactory_url</url>
        </repository>
        <snapshotRepository>
            <id>artifactory</id>
            <url>your_artifactory_url</url>
        </snapshotRepository>
    </distributionManagement>

More information about jenkins -pipline https://jenkins.io/doc/book/pipeline/