CircleCI

Mobb can be integrated into any CI/CD platform of your choice. In this guide, the process of integration with CircleCI will be demonstrated.

After logging into Mobb, select the last option in the menu: “Connect Mobb to Your Workflow”.

To run Mobb within CircleCI, select “CircleCI”.

You will be presented with a sample yaml script that you can use in CircleCI. This particular example uses Snyk as the SAST scanner, however, you may want to modify the script to use the SAST tool of your choice.

version: 2.1
orbs:
  node: circleci/node@5.2.0
jobs:
  sast-autofixer:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      
      # Installing Node.js 18
      - node/install:
          node-version: '18'
          
      - run:
          name: "Prepare Environment for SAST and Mobb Steps"
          command: |
          
            # Extract the GitHub repo URL
            GITHUBURL=$(echo $CIRCLE_REPOSITORY_URL | sed 's/^git@github.com:/https:\/\/github.com\//;s/\.git$//')
            echo "Extracted GitHub URL: $GITHUBURL"
            echo "export GITHUBURL="$GITHUBURL"" >> $BASH_ENV
            
      - run:
          name: "SAST scan"
          command: |
            # Replace this step with your own SAST scanner
            npx snyk auth $SNYK_API_KEY
            npx snyk code test --sarif-file-output=report.json
            
      - run:
          name: "Mobb Autofixer"
          command: |
            
            # Run Mobb Autofixer against the report.json file generated in the previous step with Snyk SAST scan
            MOBBURL=$(npx mobbdev@latest analyze -f report.json -r $GITHUBURL --ref $CIRCLE_BRANCH --api-key $MOBB_API_KEY --ci)
            echo "Mobb URL: $MOBBURL"
            
            # Store the Mobb URL in a html file and save it as a CircleCI artifact
            echo "<html><body><a href="$MOBBURL">Click here for the Mobb URL</a></body></html>" > mobburl.html
            
            # (Optional Step) Publish the Mobb URL back to GitHub PR page. The script can be found in https://github.com/antonychiu2/mobb-circleci-integration/tree/main/.circleci
            ./.circleci/update_github_status.sh \
              "$GITHUB_PAT_SECRET" \
              "$CIRCLE_USERNAME" \
              "$CIRCLE_PROJECT_REPONAME" \
              "$CIRCLE_SHA1" \
              "success" \
              "$MOBBURL" \
              "Click on \\\"Details\\\" to access the Mobb Fix Link" \
              "Mobb Fix Link"
          when: on_fail
          
      - store_artifacts:
          path: mobburl.html
          destination: /MobbURL
          
      - store_artifacts:
          path: report.json
          destination: /Snyk Report
# Orchestrate jobs using workflows
workflows:
  test-workflow:
    jobs:
      - sast-autofixer

Click here for a sample CircleCI job run.

Click here for a detailed sample implementation guide.

For a demonstration of how this integration works, you can visit the following YouTube video:

Last updated