Cloud customer?
Start for Free >
Upgrade in MyJFrog >
What's New in Cloud >

Search





Overview

The JFrog IDEA Plugin and the JFrog VS Code Extension allow developers to track the status of the code while it is being built, tested and scanned on the CI server. This page includes the steps required for setting up your CI pipeline to expose the information so that it is visible from the IDE.

Setting up CI integration for your IDE requires the following steps.

  1. Configuring the CI pipeline to record and publish build-info to JFrog Artifactory
  2. Creating a JFrog Platform user to be set in the IDE
  3. Configuring the IDE to display the CI information
Page contents


Set up steps

Step 1 - Configuring Your CI Pipeline to record and publish build-info to JFrog Artifactory

To set up your CI to expose the information to IDEA, you need to include the following as part of your pipeline script.

  1.  Download JFrog CLI, so that it can be used in the pipeline:

    curl -fL https://getcli.jfrog.io | sh && chmod +x jfrog
  2. Set the following environment variables with the build name and build run number. 

    export JFROG_CLI_BUILD_NAME=<the build name>
    export JFROG_CLI_BUILD_NUMBER=<the build run number>
  3. Set the following environment variable, with the URL to the pipeline log on the CI. 

    export JFROG_CLI_BUILD_URL=<url to the pipeline log>
  4. If needed, configure JFrog CLI using the following command.

    ./jfrog c add
  5. If needed, configure the repositories for your project. For example, if your code is built using maven, run:

    ./jfrog rt mvnc

     

  6. Run the command that builds your code using JFrog CLI. For example, if your code is built using maven, run: 

    ./jfrog rt mvn clean install
  7. Set the following environment variable, to indicate that the build finished successfully.

    export JFROG_BUILD_STATUS=PASS

    Make sure to set the environment variable's value to FAIL, to indicate a failure of the CI pipeline.


  8. Record the environment variables and the project's git information as part of the build-info and then, publish the build-info to Artifactory. Make sure your pipeline always executes these commands, even in the case of a failure.

    ./jfrog rt bce
    ./jfrog rt bag
    ./jfrog rt bp
  9. Optionally scan the published build with JFrog Xray by running 

    ./jfrog rt bs

JFrog Pipelines Example

 Click here to expand...
resources:
- name: mvn_example_pipelines_gitResource
  type: GitRepo
  configuration:
    path: jfrog/project-examples
    gitProvider: github_mvn_example_pipelines_integration
    buildOn:
      pullRequestCreate: true
    branches:
      include: main
- name: mvn_example_pipelines_pipeline_bi
  type: BuildInfo
  configuration:
    sourceArtifactory:    rt_mvn_example_pipelines_integration
pipelines:
  - name: mvn_example_pipelines_pipeline
    steps:
      - name: MvnBuild
        type: MvnBuild
        configuration:
          environmentVariables:
            'JFROG_CLI_BUILD_URL': $step_url
            'JFROG_BUILD_STATUS': 'PASS'
          mvnCommand:           clean install
          sourceLocation:       maven-example    
          resolverSnapshotRepo: maven-virtual
          resolverReleaseRepo:  maven-virtual
          autoPublishBuildInfo: true
          forceXrayScan:        true
          integrations:
            - name:         rt_mvn_example_pipelines_integration
          inputResources:
            - name:         mvn_example_pipelines_gitResource
          outputResources:
            - name:         mvn_example_pipelines_pipeline_bi
        execution:
          onFailure:
            - export JFROG_BUILD_STATUS=FAIL
            - jfrog rt bce
            - jfrog rt bp

Jenkins Example

 Click here to expand...
pipeline {
  agent any
  environment {
    JFROG_CLI_BUILD_NAME = "${JOB_NAME}"
    JFROG_CLI_BUILD_NUMBER = "${BUILD_NUMBER}"
    JFROG_CLI_BUILD_URL = "https://<my-jenkins-domain>/<my-job-uri>/${BUILD_NUMBER}/console"
  }
  stages {
      stage ('Clone') {
          steps {
              git branch: 'master', url: "https://github.com/jfrog/project-examples.git"
          }
      }

      stage ('Config') {
          steps {
              sh 'curl -fL https://getcli.jfrog.io | sh && chmod +x jfrog'
              sh "./jfrog c add rt-server --url https://ecosysjfrog.jfrog.io --user ${RT_USERNAME} --password ${RT_PASSWORD}"
              sh './jfrog rt mvnc --server-id-deploy rt-server --server-id-resolve rt-server --repo-resolve-releases releases --repo-resolve-snapshots snapshots --repo-deploy-releases releases-local --repo-deploy-snapshots snapshots-local' 
          }
      }

      stage ('Exec Maven') {
          steps {
              dir('maven-example') {
                  sh '../jfrog rt mvn clean install'
              }
          }
      }
  }
    
  post {
      success {
          script {
              env.JFROG_BUILD_STATUS="PASS"
          }
      }
      
      failure {
          script {
              env.JFROG_BUILD_STATUS="FAIL"
          }
      }
      
      cleanup {
          sh './jfrog rt bce'
          sh './jfrog rt bag'
          sh './jfrog rt bp'
      }
  }
}

GitHub Actions Example

 Click here to expand...

This example uses the setup-jfrog-cli GitHub Action, which already sets the JFROG_CLI_BUILD_NAME, JFROG_CLI_BUILD_NUMBER and JFROG_CLI_BUILD_URL behind the scenes.

name: 'JFrog CI Integration'
on: [push]
jobs:
 jfrog-ci-integration:
   runs-on: ubuntu-latest
   env:
     JF_ARTIFACTORY_1: ${{ secrets.JF_ARTIFACTORY_SECRET_1 }}
     JFROG_BUILD_STATUS: PASS
   steps:
     - name: Checkout
       uses: actions/checkout@v2
     - name: Setup JFrog CLI
       uses: jfrog/setup-jfrog-cli@v1
     - name: Set up JDK 11
       uses: actions/setup-java@v2
       with:
         java-version: '11'
         distribution: 'adopt'
     - name: Run Maven build
       run: |
         # Init JFrog CLI Maven config
         MVN_PATH=`which mvn` && export M2_HOME=`readlink -f $MVN_PATH | xargs dirname | xargs dirname`
         # Replace ‘my_art_server’ with your imported server
         jfrog rt mvn-config --server-id-resolve=my_art_server --repo-resolve-releases=libs-release-remote --repo-resolve-snapshots=libs-snapshot-remote
         # Build the maven project
         jfrog rt mvn clean install
     - name: Failure check
       run: |
         echo "JFROG_BUILD_STATUS=FAIL" >> $GITHUB_ENV
       if: failure()
     - name: Publish Maven build
       run: |
         # Collect environment variables for the build
         jfrog rt bce
         # Collect VCS details from git and add them to the build
         jfrog rt bag
         # Publish build info
         jfrog rt bp
         # Scan build
         jfrog rt bs
       if: always()


Step 2 - Creating a JFrog Platform user to be set in IDEA

Follow these steps to create a JFrog Platform user for IntelliJ IDEA. The user will have limited permissions, which only allows viewing the CI information inside IDEA.

  1. Make sure JFrog CLI is installed on your local machine by running 

    jfrog -v

    If it is not installed, install it.

  2. Run the following command to create a Users Group in the JFrog Platform. We'll use the name ide-developers for the Group. Feel free to choose a different name. 

    jfrog rt group-create ide-developers
  3. Run the following commands to create a Permission in the JFrog Platform. We'll use the name ide-developers-perm for the Permission. Feel free to choose a different name. Notice that the Group name we created is also included in the following commands. 

    echo {\"build\":{\"include-patterns\":\"**\"\,\"actions-groups\":{\"ide-developers\":\"read\"}}\,\"name\":\"ide-developers-perm\"} > ./perm-temp
    jfrog rt ptc ./perm-temp
    rm ./perm-temp
  4. Create the JFrog Platform user by running the following command, after replacing the <username>, <password> and <email> tokens. Notice that the Group name we created is also included in the following command. 

    jfrog rt user-create <username> <password> <email> --users-groups ide-developers

Step 3 - Now that your CI pipeline records and publishes the build-info to Artifactory, you can configure the IDE to display the CI information.

Configure IntelliJ IDEA or VS Code.

  • No labels
Copyright © 2021 JFrog Ltd.