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

Search





Overview

The MvnBuild native step performs a Maven project build on files in a Git repository. Optionally, it can also publish build information to Artifactory.

If your maven project is already using the Maven Artifactory plugin, see Setting Up Maven Builds for Pipelines for information about configuring your Maven settings for use in JFrog Pipelines.


Using this step automatically selects Java as the language and bootstraps the runtime environment in the node appropriately.

YAML Schema

MvnBuild
pipelines: 
  - name:   <string>
    steps:
      - name: <string>
        type: MvnBuild
        configuration:
          #inherits from bash
          mvnCommand:           <string>      # optional
          sourceLocation:       <string>      # optional
          resolverSnapshotRepo: <string>      # optional
          resolverReleaseRepo:  <string>      # optional
          deployerSnapshotRepo: <string>      # optional
          deployerReleaseRepo:  <string>      # optional
          forceXrayScan:        <string>      # optional
          failOnScan:           <boolean>     # default true
          autoPublishBuildInfo: <string>      # optional
          configFileLocation:   <string>      # optional
          configFileName:       <string>      # optional

          integrations:
            - name:         <Artifactory integration>  # required
          inputResources:
            - name:         <GitRepo resource>         # required
            - name:         <FileSpec resource>        # optional
          outputResources:
            - name:         <BuildInfo resource>       # if autoPublishBuildInfo is true

        execution:
          onStart:
            - echo "Preparing for work..."
          onSuccess:
            - echo "Job well done!"
          onFailure:
            - echo "uh oh, something went wrong"
          onComplete:                                  #always
            - echo "Cleaning up some stuff"
Page Contents

Tags

name 

An alphanumeric string (underscores are permitted) that identifies the step.

type 

Must be MvnBuild for this step type.

configuration

Specifies all configuration selections for the step's execution environment. This step inherits the Bash/PowerShell step configuration tags, including these pertinent  tags:

Tag

Description of usage

Required/Optional

integrationsMust specify an Artifactory IntegrationRequired
inputResources 

Must specify GitRepo resource. The mvn command performs the build on files in the Git repository at sourceLocation.

May also optionally specify a FileSpec resource that specifies what files to copy to sourceLocation to build.

Required
outputResources 

Must specify a BuildInfo resource if autoPublishBuildInfo is set to trueIf JFROG_CLI_BUILD_NAME or JFROG_CLI_BUILD_NUMBER is set as an environment variable for the pipeline or the step, that name and/or number will be used for the output BuildInfo. Otherwise, the default buildName and buildNumber are $pipeline_name and $run_number.

May be required


In addition, these tags can be defined to support the step's native operation:

Tag

Description of usage

Required/Optional
mvnCommand

Specifies a command line string of options to use with Maven.

Default is clean install.

Optional
sourceLocation

Specifies the location of the source files. By default this is set to the root directory of the GitRepo resource. Defaults to the root of the GitRepo.

Required if the source files are not in the root directory.

May be required
resolverSnapshotRepo

Artifactory repository to resolve snapshot dependencies. If set, resolverReleaseRepo is also required. 

Do not use with configFileName and configFileLocation.

Optional
resolverReleaseRepo

Artifactory repository to resolve release dependencies. If set, resolverSnapshotRepo is also required. 

Do not use with configFileName and configFileLocation.

Optional
deployerSnapshotRepo

Snapshot artifacts created by the MvnBuild are uploaded to this Artifactory repository. If set, deployerReleaseRepo is also required.

Do not use with configFileName and configFileLocation.

Optional
deployerReleaseRepo

Release artifacts created by the MvnBuild are uploaded to this Artifactory repository. If set, deployerSnapshotRepo is also required.

Do not use with configFileName and configFileLocation.

Optional
forceXrayScan

When set to true, forces an Xray scan after publishing to Artifactory. Default is false.

Optional
failOnScan

When set to  true, and  when the Xray Policy RuleFail Build  checkbox is checked, a failed Xray scan will result in a failure of the step. Default is true.

Optional
autoPublishBuildInfo

When set to true, publishes build info to Artifactory. Requires a BuildInfo resources in the outputResources list. Default is false.

Optional
configFileName

Specifies the name of the JFrog CLI mvn-config file. The serverID in the configuration file should match the Artifactory integration name. If set, configFileLocation is also required.


This option should be used only if you have committed this configuration file to your source

Optional
configFileLocation

Specifies the directory containing the JFrog CLI mvn-config file, relative to the sourceLocation . If set, configFileName is also required.

This option should be used only if you have committed this configuration file to your source

Optional


execution

Declares collections of shell command sequences to perform for pre- and post-execution phases:
TagDescription of usageRequired/Optional
onStartCommands to execute in advance of the native operationOptional
onSuccessCommands to execute on successful completionOptional
onFailureCommands to execute on failed completionOptional
onCompleteCommands to execute on any completionOptional


The actions performed for the onExecute phase are inherent to this step type and may not be overridden.


Examples

The following examples show a few ways in which a MvnBuild step can be configured

Basic Example using Default Values

The most basic form of MvnBuild. Uses all default values.  This step navigates to the root of the repo specified in the inputResources array, and performs an mvn clean install. It does not publish a build or request an Xray scan.

MvnBuild
pipelines: 
  - name: MyMavenPipeline
    steps:
      - name: MavenWithArtifactory
        type: MvnBuild
        configuration:
          integrations:
            - name: art
          inputResources:
            - name: mvn_repo

Using Artifactory as Resolver and Deployer

This example uses Artifactory as a resolver and a deployer, so that your project's dependencies are pulled from the specified repo, and the resulting artifacts are pushed back up to Artifactory. It also publishes build info to Artifactory and requests an Xray scan.

MvnBuild
pipelines: 
  - name: MyMavenPipeline
    steps:
      - name: MavenWithAll
        type: MvnBuild
        configuration:
          integrations:
            - name: art
          inputResources:
            - name: mvn_repo
          outputResources:
            - name: mvn_build_info
          mvnCommand: clean install test
          sourceLocation: mvnproject
          resolverSnapshotRepo: snapshots-remote-maven
          resolverReleaseRepo: releases-remote-maven
          deployerSnapshotRepo: snapshots-local-maven
          deployerReleaseRepo: releases-local-maven
          forceXrayScan: true
          failOnScan: true
          autoPublishBuildInfo: true

Using a Config File

This example uses a committed config file to accomplish the same thing that example 2 does.

MvnBuild
pipelines: 
  - name: MyMavenPipeline
    steps:
      - name: MvnWithConfig
        type: MvnBuild
        configuration:
          integrations:
            - name: art
          inputResources:
            - name: mvn_repo
          outputResources:
            - name: mvn_build_info
          mvnCommand: clean install test
          sourceLocation: mvnproject
          configFileLocation: "."
          configFileName: mvn-art-config
          forceXrayScan: true
          failOnScan: true
          autoPublishBuildInfo: true

How it Works

When you use the MvnBuild native step in a pipeline, it performs the following actions in the background:

MvnBuildCommands
jfrog rt config 			# configures JFrog CLI with the integration listed in the yaml
jfrog rt mvn-config 		# if configFileName and configFileLocation are not set in yaml
jfrog rt mvn $mvnCommand 	# the main maven build command
add_run_variables 			# saves some information in run state for future steps to reference
jfrog rt build-collect-env 	# collects build environment, preparing for build publish
jfrog rt build-publish 		# only if autoPublishBuildInfo is true
write_output				# updates the buildinfo resource, if present
jfrog rt build-scan 		# if forceXrayScan is true
add_run_files 				# adds BuildInfo to run state
  • No labels
Copyright © 2021 JFrog Ltd.