Blog

Jfrog and Azure DevOps Integration

Yadev KrishnaWritten by Yadev Krishna



Introduction

JFrog Artifactory is a universal DevOps solution providing end-to-end automation and management of binaries and artifacts through the application delivery process that improves productivity across your development ecosystem. It enables freedom of choice supporting 25+ software build packages, all major CI/CD platforms, and DevOps tools you already use. It is also easy to store and manage build artifacts and packages in Jfrog Artifactory compared to azure artifactory. Jfrog also manages local and remote repositories along with live replication.

Azure DevOps Server is a Microsoft product that provides version control, reporting, requirements management, project management, automated builds, testing and release management capabilities. It covers the entire application lifecycle, and enables DevOps capabilities.

In this blog, We will covering Building the mule application , packaging and uploading the mule artifact to jfrog with the build information along with how to set up the JFrog repository.

Contents:

  • Setup Jfrog
  • Integrating Jfrog With Azure Devops
  • Building mule application and uploading the mule artifact to Jfrog.
  • Downloading the artifact from Jfrog in release pipeline.

Creating Jfrog account

  1. Go to https://jfrog.com/start-free/ site to create a free tier account.

Jfrog and Azure DevOps Integration

  1. We can create a cloud Jfrog Artifactory or self-hosted artifactory. We are going with the cloud version as of now. Select Cloud and provide your first name, last name email address, and password for the account and agree to the terms and conditions, then click proceed.

Jfrog and Azure DevOps Integration

  1. Then you will be taken to an environment setup page and provide a name for your Jfrog Artifactory Server and click try now.

Jfrog and Azure DevOps Integration

  1. After clicking try now, an verification mail will be sent to you - click to verify on the email.

Jfrog and Azure DevOps Integration

  1. When you click on verify email address it takes you to a page that says take me to your environment, Click on take me to your environment and it will take you to the Jfrog homepage. Choose the options in the initial sign in page.

Jfrog and Azure DevOps Integration

You have successfully created a Jfrog free tier account.

Setting Up Artifact Repository in Jfrog

  1. Choose Artifacts from the left options, then you can see all the artifacts repositories.

Jfrog and Azure DevOps Integration

Jfrog supports many Jfrog Articfacts such as npm, Go, Gradle, maven, etc. For MuleSoft applications, we will be using maven, since Mule 4 uses maven for Mule applications life cycle management.

  1. We can see all the packages supported in Jfrog by selecting the package type in the top bar.

Jfrog and Azure DevOps Integration

We can select maven from the drop down, then we can see the all repositories related to maven projects. We need to create a Project in jfrog with a project key that will be used for publishing the artifact and the build.

  1. Go to Jfrog , and go to projects in administration tab.

Jfrog and Azure DevOps Integration

  1. Click On Create New .

Then give a project name, project key, and then click Create

Jfrog and Azure DevOps Integration

  1. Now we need to create a repository in the project., for that click on the project in the project tab.

In the window that opens click on create repository, we can also assign a repository that is already created, but we will be creating a new repository.

Click on create repository > Local respository

Jfrog and Azure DevOps Integration

Select maven as package manager . Give the repository a name , and click on create local repository.

  1. If we need to see the repository that we created

Go the artifact in the artifactory.

Jfrog and Azure DevOps Integration

Now our repository is created . we need to give necessary permissions to read and write to the repository. For that make sure you select all in the project.

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

  1. Then in the administration tab , Select Global roles in identity and access

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

Make sure you do not miss this step , because , will not be able to write to the repository , if we did not give the permission.

This is it, we are done with the jfrog set up. Next we need to setup jfrog connection in azure Devops .

Setting Jfrog Connection in Azure DevOps

  1. Login to your azure devops account and Install jfrog plugin from the azure marketplace.

Jfrog and Azure DevOps Integration

  1. Go to the project in azure Devops and then navigate to project settings > Service Connections > Create service connection
  2. Search Jfrog and select jfrog artifactory , then click on next

Jfrog and Azure DevOps Integration

  1. Select basic authentication.provide the artifactory url and add /artifactory in the server url and provide username and password and name for the service connection .Click on verify to check the connection and click save.

Jfrog and Azure DevOps Integration

Now we are done with the setup of jfrog in azure DevOps . We need to have mule project and in any source code management of choice , here we are using the repo provided by Azure DevOps . There is a mule hello world application pushed.

Jfrog and Azure DevOps Integration

  1. Azure pipeline Yaml
trigger:
- master

pool:
  vmImage: ubuntu-latest

variables:
- name: MAVEN_CACHE_FOLDER
  value: $(Pipeline.Workspace)/.m2/repository
- name: MAVEN_OPTS
  value: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'

stages:
- stage: Build
  displayName: ProjectBuild
  jobs:
  - job: Build
    steps:
        - task: CacheBeta@0
          inputs:
            key: $(Build.SourcesDirectory)/pom.xml
            path: $(MAVEN_CACHE_FOLDER) 
        - task: Maven@3
          inputs:
            mavenPomFile: 'pom.xml'
            mavenOptions: '-Xmx3072m'
            javaHomeOption: 'JDKVersion'
            jdkVersionOption: '1.8'
            jdkArchitectureOption: 'x64'
            goals: 'package -DskipMunitTests -DvaultKey=$(vaultKey) $(MAVEN_OPTS)'

        - task: CopyFiles@2
          inputs:
            Contents: '**/target/*.jar'
            TargetFolder: $(Build.ArtifactStagingDirectory) 
            CleanTargetFolder: true
            flattenFolders: true  
        - task: PublishPipelineArtifact@1
          inputs:
            targetPath: $(Build.ArtifactStagingDirectory)
            artifactName: 'drop'

- stage: Jfrog
  displayName: Jfrog
  jobs:
  - job: ArtifactArchivingStage
    steps:
      - task: DownloadPipelineArtifact@2
        inputs:
          buildType: 'current'
          artifactName: 'drop' 
          targetPath: '$(Pipeline.Workspace)'
      - task: ArtifactoryGenericUpload@2
        inputs:
          artifactoryService: 'jfrog-server'
          specSource: 'taskConfiguration'
          fileSpec: |
            {
                          "files": [
                            {
                              "pattern": "$(Pipeline.Workspace)/*.jar",
                              "target": "$(repository-name)"
                            }
                          ]
                        }
          collectBuildInfo: true
          buildName: '$(Build.DefinitionName)'
          buildNumber: '$(Build.BuildNumber)'
          projectKey: '$(project-key)'
          failNoOp: true
      - task: ArtifactoryPublishBuildInfo@1
        inputs:
          artifactoryService: 'jfrog-server' 
          buildName: '$(Build.DefinitionName)'
          buildNumber: '$(Build.BuildNumber)'
          projectKey: '$(project-key)'
      
  1. The first stage in the build stage , where we build the application and publish the mule app jar as a pipeline artifact in the name drop.

  2. Next stage is downloading the pipeline artifact , uploading the jar and publishing the build info to jfrog.

We can get all the tasks in the azure devops task palette.

Tasks

  • The first task is Downloading the published artifact to this stage . Because , in between stages , the data will be lost. That is why we are publishing the artifact in the first place.We are downloading the artifact to the pipeline workspace.
  • ArtifactoryGenericUpload task: This task is to upload the pipeline artifact to jfrog . We will be able to use this task only if we install the Jfrog plugin. Search for generic upload in the tasks

Jfrog and Azure DevOps Integration

Artifactory service : Select Jfrog connection name

Spec : contains all the specifications related to the artifact.

In this configuration it will take all the jar files in the pipeline directory and upload to the target repository in the jfrog , here “demo-demo-repository”

  • Artifactory Publish build info

Jfrog and Azure DevOps Integration

  1. Now save and run the pipeline.

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

Jfrog and Azure DevOps Integration

Conclusion

You have now successfully used Jfrog Artifact with Azure DevOps.

References :

  1. https://www.youtube.com/watch?v=1QwyWikh-Qk&t=754s
  2. https://www.jfrog.com/confluence/display/JFROG/Artifactory+Azure+DevOps+Extension