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





Overview

TheGradleBuildnative step performs a Gradle build on files in a Git repository.Optionally, it can also publish build information to Artifactory.


This step utilizes the JFrog CLI to run a Gradle build for your project. The CLI config file can be created during execution, or you can generate it ahead of time with the settings you require and commit it to your repository. For information about gradle-config, seeCLI for JFrog Artifactory#Settinggradlerepositories.

Page Contents


YAML Schema

The YAML schema for GradleBuild native step is as follows:

GradleBuild
pipelines: - name:  steps: - name:  type: GradleBuild configuration: #inherits all the tags from bash; //www.si-fil.com/confluence/display/JFROG/Bash gradleCommand:  #required sourceLocation:  #optional configFileLocation:  #optional configFileName:  #optional resolverRepo:  #optional deployerRepo:  #optional usesPlugin:  #optional useWrapper:  #optional forceXrayScan:  #optional failOnScan:  #optional; default true autoPublishBuildInfo:  #optional inputResources: - name: myGitRepo - name: artifactoryFileSpec outputResources: - name: myBuildInfo integrations: - name: myArtifactory 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"

Tags

name

Analphanumericstring (underscores are permitted) that identifies the step.

type

Must beGradleBuildfor this step type.

configuration

Specifies all configuration selections for the step's execution environment.This step inherits theBash/PowerShellstep configuration tags, including these pertinenttags:

Tag

Description of usage

Required/Optional

integrations Must specify anArtifactory Integration. Required
inputResources

Must specifyaGitReporesource.The Gradle command will perform the build on files in the Git repository atsourceLocation.

May also optionally specify aFileSpecresourcethat specifies what files to copy tosourceLocationto build.

Required
outputResources

Must specify aBuildInforesource ifautoPublishBuildInfois set totrue.

IfJFROG_CLI_BUILD_NAMEorJFROG_CLI_BUILD_NUMBERis set as an environment variable for the pipeline or the step, that name and/or number is used for the output BuildInfo. Otherwise, the defaultbuildNameandbuildNumberare$pipeline_nameand$run_number.

May be required


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

Tags derived from Bash

来自本地所有步骤Bashstep. This means that all steps share the same base set of tags from Bash, while native steps have their own additional tags as well that support the step's particular function. So it's important to be familiar with theBashstep definition, since it's the core of the definition of all other steps.

Tag

Description of usage

Required/Optional
gradleCommand Specifies a command line string of options to use with the Gradle build tool. Required
sourceLocation Location of the source files to build relative to the root of the GitRepo repository. If no path is specified, the root of the repository will be used. Optional
resolverRepo Artifactory repository to be used to resolve dependencies. May not be used withconfigFileNameandconfigFileLocation. Optional
deployerRepo Artifactory repository to which to deploy. May not be used withconfigFileNameandconfigFileLocation. Optional
usesPlugin

Set totrueif the Gradle Artifactory Plugin is already applied in the build script. Default is歧视se.

Do not use withconfigFileNameandconfigFileLocation(you can enable this option directly in your existing config file).

Optional
useWrapper

If set totrue, use the Gradle wrapper. Default is歧视se.

Do not use withconfigFileNameandconfigFileLocation(you can enable this option directly in your existing config file).

Optional
forceXrayScan

When set totrue, forces an Xray scan after publishing to Artifactory.

Default is歧视se.

Optional
failOnScan

When set totrue, andwhen the XrayPolicy RuleFail Buildcheckbox is checked, a failed Xray scan will result in a failure of the step.

Default istrue.

Optional
autoPublishBuildInfo

When set totrue, publishes build info to Artifactory.

Default is歧视se.

Optional
configFileName

Gradle configuration file. If specified, theconfigFileLocation标签也是required. This file is generated using the JFrog CLI when you runjfrog rt gradle-configcommand.

TheserverIDin the configuration file should match the Artifactory integration name.

Use this option only if you have committed this configuration file to your source.

Optional
configFileLocation Gradle configuration file location. AconfigFileName标签也是required. Typically stored in the.jfrogdirectory in the repository. Optional


execution

Declares collections of shell command sequences to perform for pre- and post-execution phases:

Tag Description of usage Required/Optional
onStart Commands to execute in advance of the native operation Optional
onSuccess Commands to execute on successful completion Optional
onFailure Commands to execute on failed completion Optional
onComplete Commands to execute on any completion Optional


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


Examples

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

Using Default Values

The most basic form of GradleBuild. Uses all default values. This step will navigate to the root of the repo specified in the inputResources array, and run the specified Gradle command.

GradleBuild
pipelines: - name: gradleBuildPipeline steps: - name: gradleBuildStep type: GradleBuild configuration: gradleCommand: "build" inputResources: - name: gitRepoResource integrations: - name: artifactory_integration

源位置是Git存储库的子目录

A more complicated GradleBuild step, in this one the source location is a subdirectory of the GitRepo (gradle-example-minimal) and the project uses theGradle Artifactory Plugin. Resolver and deployer repositories have also been configured, resolving from jcenter and deploying to gradle-local.

GradleBuild
pipelines: - name: gradleBuildPipeline steps: - name: gradleBuildStep type: GradleBuild configuration: gradleCommand: "artifactoryPublish clean -b build.gradle" sourceLocation: gradle-example-minimal deployerRepo: gradle-local resolverRepo: jcenter usesPlugin: true inputResources: - name: gitRepoResource integrations: - name: artifactory_integration

Using Config File

This GradleBuild step is similar to the previous example, but has aconfig file committed to the repository as gradle-example-minimal/gradle-art-config. The config file contains the repository and plugin settings.

GradleBuild
pipelines: - name: gradleBuildPipeline steps: - name: gradleBuildStep type: GradleBuild configuration: gradleCommand: "artifactoryPublish clean -b build.gradle" sourceLocation: gradle-example-minimal configFileLocation: . configFileName: gradle-art-config inputResources: - name: gitRepoResource integrations: - name: artifactory_integration

Publish Build Info and Trigger Xray Scan

In this example, build info is published as part of the GradleBuild step and an Xray scan is triggered.

GradleBuild
pipelines: - name: gradleBuildPipeline steps: - name: gradleBuildStep type: GradleBuild configuration: gradleCommand: "build" autoPublishBuildInfo: true forceXrayScan: true inputResources: - name: gitRepoResource integrations: - name: artifactory_integration outputResources: - name: myBuildInfo

How it Works

When you use theGradleBuildnative step in a pipeline, it performs the following functions in the background:

  • jfrog rt config (configure JFrog CLI with the integration listed in the yaml)
  • jfrog rt gradle-config (if configFileName and configFileLocation are not set in yaml)
  • jfrog rt gradle $gradleCommand (the main gradle build command)
  • add_run_variables (save information in run state for future steps to reference)
  • jfrog rt build-collect-env (collect the build environment, preparing for build publish)
  • jfrog rt build-publish (publish the build, only if autoPublishBuildInfo is true)
  • write_output (update the BuildInfo output resource with the published name/number)
  • jfrog rt build-scan (if forceXrayScan is true)
  • add_run_files (adds build info to run state)
  • No labels
Copyright © 2022 JFrog Ltd.