MavenCI

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

The MavenCI template creates a pipeline that showcases the features of the MvnBuild native step. These features include:

  • Building a Maven project and pushing the resulting artifacts to Artifactory

  • Publishing an Artifactory build and updating an output BuildInfo resource

  • Utilizing JFrog Xray to scan the artifacts for security vulnerabilities

  • Writing to an output FileSpec resource that can be connected to another pipeline

This template requires a few configurations to be set up:

  • An Artifactory integration or JFrog Platform Access Token Integration for resolving dependencies and publishing artifacts

  • A Git integration (like GitHub) that can connect with your Maven projectGitHub Integration

  • Resolver and deployer Artifactory Maven repositories for snapshots and releases

MavenCI YAML

resources:
  - name: {{ .Values.namePrefix }}_repo
    type: GitRepo
    configuration:
      path: {{ .Values.repo.path }}
      gitProvider: {{ .Values.repo.gitIntegration }}
      branches:
        include: {{ .Values.repo.branchPattern | default "main" }}

{{ if .Values.publishBuild }}
  - name: {{ .Values.namePrefix }}_info
    type: BuildInfo
    configuration:
      sourceArtifactory: {{ .Values.artIntegration }}

  - name: {{ .Values.namePrefix }}_spec
    type: FileSpec
    configuration:
      sourceArtifactory: {{ .Values.artIntegration }}
      pattern: '{{ .Values.buildSpecPattern | default "*" }}'
      buildName: ${JFROG_CLI_BUILD_NAME}
      buildNumber: ${JFROG_CLI_BUILD_NUMBER}
{{ end }}


pipelines:
  - name: {{ .Values.namePrefix }}_maven_ci
{{ if .Values.publishBuild }}
    configuration:
      environmentVariables:
        readOnly:
          JFROG_CLI_BUILD_NAME: ${pipeline_name}
          JFROG_CLI_BUILD_NUMBER: ${run_id}
{{ end }}
    steps:
      - name: build
        type: MvnBuild
        configuration:
          integrations:
            - name: {{ .Values.artIntegration }}
          inputResources:
            - name: {{ .Values.namePrefix }}_repo
        {{ if .Values.publishBuild }}
          outputResources:
            - name: {{ .Values.namePrefix }}_info
            - name: {{ .Values.namePrefix }}_spec
          autoPublishBuildInfo: true
        {{ end }}
        {{ if and .Values.scanBuild .Values.publishBuild }}
          forceXrayScan: true
        {{ end }}
        {{ if .Values.mavenConfig.command }}
          mvnCommand: {{ .Values.mavenConfig.command }}
        {{ end }}
        {{ if .Values.mavenConfig.sourceLocation }}
          sourceLocation: {{ .Values.mavenConfig.sourceLocation }}
        {{ end }}
        {{ if .Values.mavenConfig.resolverSnapshotRepo }}
          resolverSnapshotRepo: {{ .Values.mavenConfig.resolverSnapshotRepo }}
        {{ end }}
        {{ if .Values.mavenConfig.deployerSnapshotRepo }}
          deployerSnapshotRepo: {{ .Values.mavenConfig.deployerSnapshotRepo }}
        {{ end }}
        {{ if .Values.mavenConfig.resolverReleaseRepo }}
          resolverReleaseRepo: {{ .Values.mavenConfig.resolverReleaseRepo }}
        {{ end }}
        {{ if .Values.mavenConfig.deployerReleaseRepo }}
          deployerReleaseRepo: {{ .Values.mavenConfig.deployerReleaseRepo }}
        {{ end }}
      {{ if .Values.publishBuild }}
        execution:
          onSuccess:
            - write_output {{ .Values.namePrefix }}_spec buildName="${JFROG_CLI_BUILD_NAME}"
            - write_output {{ .Values.namePrefix }}_spec buildNumber="${JFROG_CLI_BUILD_NUMBER}"
      {{ end }}

values.yml: This is a samplevalues.yml. This can be edited to create your own version of the file.

## This string will prefix the resources and pipeline.
## It will allow you to add a pipeline source from this
## template multiple times with unique names.
namePrefix: sample

## The name of your Artifactory integration
artIntegration: myArtIntegrationName

##### Artifactory Build Info
## set this to `true` to publish a build
#publishBuild: true
## set this to `true` to scan the published build
#scanBuild: true
## When publishBuild is enabled, a FileSpec resource will be created
## that points to the published build. Here you can specify a pattern
## to further narrow down the Artifacts that are referenced by the spec.
#buildSpecPattern: "*"

##### Repository Details
repo:
  path: org/repo
  gitIntegration: myGitIntegration
  branchPattern: "^main$"

##### Maven configuration
mavenConfig:
  ## Here you specify the command to execute
  ## it is executed as `mvn {{ command }}`
  command: clean install
  sourceLocation: "MavenCI/sample-project"
  ## These repos must first be created in Artifactory.
  ## resolver is used to resolve dependencies. It is recommended to
  ## use a remote repository so that any external dependencies will be cached
  ## in your local Artifactory instance. Deployer is where your Artifacts
  ## will be uploaded.
  resolverSnapshotRepo: maven-snapshot-remote
  resolverReleaseRepo: maven-release-remote
  deployerSnapshotRepo: maven-snapshot-local
  deployerReleaseRepo: maven-release-local