GradleCI

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

See it Live

Click here to see this Global template in action.

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

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

  • Publishing an Artifactory build and updating an output BuildInfo resources

  • Utilizing JFrog Xray to scan the artifacts for security vulnerabilities

  • Writing to an output FileSpec resources 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 Gradle projectGitHub Integration

  • Resolver and deployer Artifactory repositories

  • A Gradle command to run as part of the GradleBuild step (the part following "gradle")

GradleCI 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 }}_gradle_ci
{{ if .Values.publishBuild }}
    configuration:
      environmentVariables:
        readOnly:
          JFROG_CLI_BUILD_NAME: ${pipeline_name}
          JFROG_CLI_BUILD_NUMBER: ${run_id}
{{ end }}
    steps:
      - name: build
        type: GradleBuild
        configuration:
          integrations:
            - name: {{ .Values.artIntegration }}
          inputResources:
            - name: {{ .Values.namePrefix }}_repo
        {{ if .Values.publishBuild }}
          outputResources:
            - name: {{ .Values.namePrefix }}_info
            - name: {{ .Values.namePrefix }}_spec
        {{ end }}
        {{ if .Values.publishBuild }}
          autoPublishBuildInfo: true
        {{ end }}
        {{ if and .Values.scanBuild .Values.publishBuild }}
          forceXrayScan: true
        {{ end }}
        {{ if .Values.gradleConfig.command }}
          gradleCommand: {{ .Values.gradleConfig.command }}
        {{ end }}
        {{ if .Values.gradleConfig.sourceLocation }}
          sourceLocation: {{ .Values.gradleConfig.sourceLocation }}
        {{ end }}
        {{ if .Values.useWrapper }}
          useWrapper: true
        {{ end }}
        {{ if .Values.gradleConfig.resolverRepo }}
          resolverRepo: {{ .Values.gradleConfig.resolverRepo }}
        {{ end }}
        {{ if .Values.gradleConfig.deployerRepo }}
          deployerRepo: {{ .Values.gradleConfig.deployerRepo }}
        {{ 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 sample values.yml. This can be edited to create your own version of the file.

## This string will prefix the resources and pipeline, allowing you to add
## the pipeline source 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$"

##### Gradle configuration
gradleConfig:
  ## Here you specify the command to execute
  ## it is executed as `gradle {{ command }}`
  command: "hello"
  sourceLocation: "."
  ## These repositories must first be created in Artifactory.
  ## The 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.
  resolverRepo: gradle-remote
  deployerRepo: gradle-local
  ## If your project uses the Gradle Wrapper set useWrapper to true
  #useWrapper: true