Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 15, 2019 02:31 pm GMT

CI/CD Building a pipeline used by multiple repositories with Jenkins and Artifactory integration

This guide allows you to execute Maven builds of multiple bitbucket repositories with a single pipeline on Jenkins, resolve the dependencies from Artifactory and deploy artifacts and buildinfo to Artifactory. Even if Im using Bitbucket (based on Git), this can be easily replaced with Github or other versioning control tools supported by Jenkins.
All the code that I wrote for this tutorial is available on GitHub.

1. Install Jenkins and JFrog Artifactory

2. Add a webhook on your BitBucket repositories to trigger the Jenkins job when a commit is pushed. The URL is just the address of the machine where Jenkins is installed + /bitbucket-hook/. Make it sure to write the / at the end of the URL because itll not work without it.

Bitbucket webhook

3. Configure Maven and JDK on Manage Jenkins > Global Tool Configuration

Maven Setup

JDK Setup
N.B. Use Install Automatically only if Jenkins is running on a RedHat machine, otherwise it will throw an IllegalArgumentException

4. Create the repositories on Artifactory

  • Create a local repository on Artifactory

Local Repo Artifactory

  • Create a virtual repository containing the local one

Virtual Repo Artifactory

5. Configure Artifactory on Jenkins on Manage Jenkins > Configure System
Artifactory Setup

In order to resolve your dependencies from Artifactory when a build is executed on Jenkins, you need to set the settings.xml

  • Generate settings.xml from Artifactory by going on your virtual repository and then Set Me Up > Generate Maven Settings
  • Go on Manage Jenkins > Managed Files > Add a new Config and insert your settings.xml here (you need Config File Provider Plugin)
  • If you want to resolve the dependencies from Artifactory during your local builds as well, put the settings.xml also at %USERPROFILE%.m2\settings.xml. Your repository configuration should look like this:

6. Create a Jenkins Job by clicking on New Item >Bitbucket Team/Project (you need Bitbucket Branch Source Plugin for this).

  • Put your bitbucket owner and credentials under Projects. After doing so your job will be able to scan automatically all your projects
  • Create a repository containing only a Jenkinsfile with your pipeline. In this case the pipeline that were going to use looks like this:
  • Connect your Jenkinsfile to your job. To do this go to the job configuration, under Projects click on Add > Remote File Plugin (you need to install Remote File Plugin). Under Local File put pom.xml, so that Jenkins can recognize to trigger the pipeline for every repository that has a pom

Remote File Plugin

7. Try it out! I have two repositories on bitbucket: jenkins-project1 and jenkins-project2. The latter depends on the former, so that I can test whether the dependencies are resolved from Artifactory correctly. Lets try building project1 and then project2
Build Project1
Build Project2

Congratulations! You successfully integrated Artifactory and Jenkins with multiple repository by creating only one pipeline. If you want to have a look of the projects that I built on this tutorial, you can find them on GitHub.


Original Link: https://dev.to/robertobatts/ci-cd-building-a-pipeline-used-by-multiple-repositories-with-jenkins-and-artifactory-integration-3kk5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To