This plugin adds Gradle Support to Jenkins. Gradle is managed as another tool inside Jenkins (the same way as Ant or Maven), including support for automatic installation and a new build step is provided to execute Gradle tasks.
It also allows detecting Build Scans in arbitrary console logs, for Maven and Gradle builds and display them in the Jenkins UI.
You can have the Gradle Enterprise Gradle plugin and the Gradle Enterprise Maven extension automatically injected into your Gradle and Maven builds. See Gradle Enterprise integration for more details.
Gradle configuration is performed in the Configure System (before Jenkins 2.0) or Global Tool Configuration (starting in Jenkins 2.0). In both cases these options reside in the Manage Jenkins section.
In the Gradle section provided by this plugin, several installations can be configured:
The system provides both automatic installation, which can be performed by directly downloading a Gradle distribution from the Gradle website or executing some shell commands to achieve the same.
Besides, for nodes which already have Gradle installed, the tool can be manually configured, by unchecking the Install automatically checkbox and providing the base path (as a GRADLE_HOME
environment variable) of the installation.
The Gradle plugin provides an Invoke Gradle script build step.
The first configuration option is whether to use one of the installation configured in Jenkins (see previous section) of use the Gradle Wrapper which is the Gradle-provided mechanism to "embed" the use of a specific Gradle version in a build, installing it if necessary.
Other configuration options include:
-
A description to use for the build step.
-
Switches (options) to provide to the Gradle execution.
-
Tasks to execute (if blank the defaults tasks of the build will be invoked).
-
Path to the build script if different from the root directory of the build.
-
Name of the build script if different from
build.gradle
.
If a Gradle Build Scan is produced during a build, then a link to it is added to the build page.
If you are not using the Gradle build step described above, or have a Maven build, you can configure to detect published build scans from the console log. For doing so, go to Build Environment and check Inspect build log for published build scans.
If build scans are detected in the console log of a build, a badge will be added to the build page. This works for build scans produced by Gradle and Maven builds.
When using Jenkins pipeline, there is the build step wrapper withGradle
which can be used to find the build scans emitted by Gradle or Maven builds and show them on the build page.
In order to do so, wrap your sh
or bat
steps which invoke Gradle or Maven into withGradle
.
For example:
node {
withGradle {
sh './gradlew build'
}
}
This causes the shell output to be highlighted and build scan links, which are published, are captured. The captured build scan links are then shown on the build page and in the pipeline steps view.
There is also the findBuildScans()
step, which finds the build scans in the complete log of the pipeline job.
The withGradle
wrapper should be used instead, since it also deals well with parallel output.
Build scans links on the Job summary page can be enriched with data fetched from the Gradle Enterprise server API. If enabled, the project name, requested tasks, build tool version, build outcome and build scan links will be provided. This feature is available for both Gradle and Maven builds and compatible with auto-injection documented below.
Note - Build scans published on the public instance (https://scans.gradle.com) are not eligible.
Note - Enabling this feature will trigger 2 HTTP requests to the Gradle Enterprise server per build scan published.
The plugin can be configured to inject the Gradle Enterprise Gradle plugin or the Gradle Enterprise Maven extension into any Gradle or Maven build that is executed on the Jenkins server or on any of its connected agents.
To achieve this, the plugin installs various files on each agent depending on the configuration via the global options in the Manage Jenkins/Configure System
section.
The same auto-injection behavior is available for the Common Custom User Data Gradle plugin and the Common Custom User Data Maven extension.
Note - The configuration applies to all builds on all connected agents matching the specified label criteria, or all in case no label criteria are defined.
The auto-injection is split into several levels to have fine-grained control over the enablement of this feature.
To globally enable the auto-injection, click the Enable auto-injection
checkbox in the Gradle Enterprise integration
section of the global options in the Manage Jenkins/Configure System
section.
Next set the URL of the Gradle Enterprise instance to which the build scans should be published to.
Optionally you can click the Enforce Gradle Enterprise server url
checkbox to enforce the configured Gradle Enterprise URL over a URL configured in the project’s build (only applies to Gradle projects).
It is also possible to enable/disable injection for specific repositories by specifying VCS repository filters. These are Newline-delimited set of rules in the form of +|-:repository_matching_keyword
, which will be used in a contains check against the repository URL.
Consider the following examples:
+:foo
The injection will only be performed for Git repository URLs which contain foo
.
-:foo
The injection will not be performed for Git repository URLs which contain foo
, but will be for all others.
+:foo
-:foobar
The injection will be performed for Git repository URLs which contain foo
, but not the ones containing foobar
.
The exclusion patterns take precedence over the inclusion patterns.
Note - This feature is currently in Beta and requires Git Plugin to be installed. If Git Plugin is not installed, the following warning message will be show instead. The feature supports both Gradle and Maven builds (FreeStyle and Pipeline job configurations)
To enable the auto-injection for Gradle builds, set the desired Gradle Enterprise Gradle plugin version in the Gradle Enterprise Gradle plugin version
field in the Gradle settings
section of the configuration form.
Optionally set the desired version of the Common Custom User Data Gradle plugin to be used.
To enable the auto-injection for Maven builds, click the Enable Gradle Enterprise Maven extension auto-injection
checkbox in the Maven settings
section of the configuration form.
Optionally click the Enable Common Custom User Data Maven extension auto-injection
checkbox to enable the auto-injection of the Common Custom User Data Maven Extension.
To see which versions are injected, refer to Auto-injection compatibility.
Warning - Maven injection only works if
MAVEN_OPTS
is not configured as a global environment variable.
Disabling the auto-injection requires that all Gradle Enterprise resources are cleaned up from the agents.
To achieve this, the Gradle or Maven injections must be disabled individually (see the following sections).
This triggers a cleanup of the resources.
If the auto-injection should be disabled globally, then uncheck the Enable auto-injection
checkbox as well.
To disable the auto-injection for Gradle builds, remove the Gradle Enterprise Gradle plugin version
in the Gradle settings
section of the configuration form.
Auto-injection can be enabled or disabled based on specific node labels.
To enable auto-injection only on specific nodes, add the desired labels to the Gradle auto-injection enabled nodes
list for Gradle or Maven auto-injection enabled nodes
for Maven.
To disable auto-injection on specific nodes, add the desired labels to the Gradle auto-injection disabled nodes
list for Gradle or Maven auto-injection disabled nodes
for Maven.
The disabled labels list will take precedence over the enabled labels list.
The following sections list all available configuration options which can be set via the configuration form.
Enable auto-injection
Globally enable auto-injection.
Gradle Enterprise server url
The URL of the Gradle Enterprise instance.
Allow untrusted server
Whether to allow publishing to a server with a self-signed certificate.
Gradle Enterprise access key
The access key for authenticating with the Gradle Enterprise server.
The access key is stored encrypted within the Jenkins instance. During the job execution, the access key is decrypted and set as GRADLE_ENTERPRISE_ACCESS_KEY
environment variable.
Refer to the Gradle Enterprise Gradle plugin manual and the Gradle Enterprise Maven Extension manual for more details about this configuration.
Gradle Enterprise Gradle plugin version
Enables auto-injection for Gradle builds and defines which version of the Gradle Enterprise Gradle plugin to use.
Common Custom User Data Gradle plugin version
Defines which version of the Common Custom User Data Gradle plugin to use.
Gradle plugin repository url
The URL of the repository to use to resolve the Gradle Enterprise Gradle plugin and the Common Custom User Data Gradle plugin.
This is required if the Jenkins agents are not able to access the Gradle Plugin Portal.
Gradle auto-injection enabled nodes
A list of node labels on which the Gradle Enterprise Gradle plugin or Common Custom User Data Gradle plugin injection should be enabled.
By default, all nodes are enabled.
Gradle auto-injection disabled nodes
A list of node labels on which the Gradle Enterprise Gradle plugin or Common Custom User Data Gradle plugin injection should be disabled.
By default, all nodes are enabled.
Enable Gradle Enterprise Maven extension auto-injection
Enables auto-injection for Maven builds and injects Gradle Enterprise Maven extension.
Enable Common Custom User Data Maven extension auto-injection
Enables auto-injection of Common Custom User Data Maven extension.
Maven auto-injection enabled nodes
A list of node labels where the Gradle Enterprise Maven extension or Common Custom User Data Maven extension injection should be enabled.
By default, all nodes are enabled.
Maven auto-injection disabled nodes
A list of node labels where the Gradle Enterprise Maven extension or Common Custom User Data Maven extension injection should be disabled.
By default, all nodes are enabled.
The following sections list the compatibility of the plugin with the Gradle Enterprise version based on the given build tool in use.
For Gradle builds the version used for the Gradle Enterprise Gradle plugin is defined in the Gradle Enterprise Gradle plugin version
field in the Gradle settings
section of the configuration form.
See Enable auto-injection for details.
The compatibility of the specified version with Gradle Enterprise can be found here.
For the optional Common Custom User Data Gradle plugin which is defined the same form, you can see the compatibility of the specified version with the Gradle Enterprise Gradle plugin here.
For Maven builds the version of the Gradle Enterprise Maven extension is bundled into the plugin, meaning that the user can’t change what version is injected into the Maven build.
The following table shows the compatibility of the plugin version with Gradle Enterprise:
Jenkins Gradle Plugin version |
Injected Gradle Enterprise Maven extension version |
Injected Common Custom User Data Maven extension version |
Minimum supported Gradle Enterprise version |
Next version |
1.19.1 |
1.12.3 |
2023.3 |
2.8.2 |
1.18.1 |
1.12.2 |
2023.2 |
2.8.1 |
1.17.3 |
1.12 |
2023.1 |
2.8 |
1.17.3 |
1.12 |
2023.1 |
2.7 |
1.17.2 |
1.11.1 |
2023.1 |
2.6 |
1.17.1 |
1.11.1 |
2023.1 |
2.5.1 |
1.17 |
1.11.1 |
2023.1 |
2.5 |
1.17 |
1.11.1 |
2023.1 |
2.4 |
1.16.6 |
1.11.1 |
2022.4 |
2.3.2 |
1.16.5 |
1.11.1 |
2022.4 |
2.3.1 |
1.16.5 |
1.11.1 |
2022.4 |
2.3 |
1.16.4 |
1.11.1 |
2022.4 |
2.2 |
1.16.1 |
1.11.1 |
2022.4 |
2.1.1 |
1.15.5 |
1.11.1 |
2022.3 |
2.1 |
1.15.4 |
1.11.1 |
2022.3 |
2.0 |
1.15.4 |
1.11.1 |
2022.3 |
1.40 |
1.15.3 |
1.11.1 |
2022.3 |
< 1.40 |
Not supported |
Not supported |
Not supported |
To ensure that all Gradle Enterprise resources are cleaned up from the agents, before disabling/uninstalling the plugin the auto-injection has to be manually disabled. Please, refer to the Disable auto-injection section for details.
Note - These upgrade notes only apply if you configured the Gradle Enterprise auto-injection feature.
A new form based configuration was introduced in this version, which replaces the configuration via environment variables. There is no automatic migration, therefore you need to manually migrate the already configured auto-injection via environment variables you’d need to follow these steps:
-
Copy the values of the following environment variables and then remove them in the global configuration following environment variables from the global configuration:
-
JENKINSGRADLEPLUGIN_GRADLE_ENTERPRISE_INJECTION
-
JENKINSGRADLEPLUGIN_GRADLE_ENTERPRISE_URL
-
JENKINSGRADLEPLUGIN_GRADLE_ENTERPRISE_ALLOW_UNTRUSTED_SERVER
-
GRADLE_ENTERPRISE_ACCESS_KEY
-
JENKINSGRADLEPLUGIN_GRADLE_ENTERPRISE_PLUGIN_VERSION
-
JENKINSGRADLEPLUGIN_CCUD_PLUGIN_VERSION
-
JENKINSGRADLEPLUGIN_GRADLE_PLUGIN_REPOSITORY_URL
-
JENKINSGRADLEPLUGIN_GRADLE_INJECTION_ENABLED_NODES
-
JENKINSGRADLEPLUGIN_GRADLE_INJECTION_DISABLED_NODES
-
JENKINSGRADLEPLUGIN_GRADLE_ENTERPRISE_EXTENSION_VERSION
-
JENKINSGRADLEPLUGIN_CCUD_EXTENSION_VERSION
-
JENKINSGRADLEPLUGIN_MAVEN_INJECTION_ENABLED_NODES
-
JENKINSGRADLEPLUGIN_MAVEN_INJECTION_DISABLED_NODES
-
-
Copy the previously saved values and enter them in the new form based configuration to have the same configuration as before.
For the current release notes (v1.34+
), please check the GitHub releases page.
For the older releases < v1.34
see this list:
-
Expose build scan action via Jenkins API (#70)
-
Support detecting build scans for non-Gradle build steps #66
-
Support for detecting Maven build scans #68
-
Fix configuration as code compatibility (JENKINS-53575)
-
Update licensing information in pom.xml.
-
Support console annotations for Gradle 4.7 and later.
-
Empty job parameters are passed as empty (JENKINS-45300)
-
Console annotator endless loop in combination with using the Ant plugin fixed (JENKINS-46051)
-
Increase required core version to 1.642.1
-
Make finding wrapper location more robust on Windows
-
Job parameters are now correctly quoted when passed as system properties (JENKINS-42573 and JENKINS-20505)
-
Do not pass all job parameters as (system) properties to Gradle by default
-
Include automated test for CLI command JENKINS-42847
-
Ensure that Gradle’s bin directory is on the path for Pipeline tool steps JENKINS-42381
-
Add option to pass only selected system properties to Gradle
-
Add option to pass only selected project properties to Gradle
-
Progress status
FROM-CACHE
andNO-SOURCE
are highlighted in the console, too. -
Support build scan plugin 1.8
-
DO NOT USE - PROBLEMS WITH RELEASING JENKINS-45126
-
Use
@DataBoundSetter
instead of a (too) large@DataBoundConstructor
-
Add @Symbol annotations for step and tool JENKINS-37394
-
Make it possible to configure the wrapper location JENKINS-35029
-
Update icon for build scan integration
-
Remove description from build step
-
Update core dependency to 1.580.1 JENKINS-34790
-
Fix for Gradle wrapper not working when Gradle version was previously selected (JENKINS-24682)
-
Long task names in console outline should not overlap console output (JENKINS-26287)
-
It is now possible to pass Gradle build parameters as project properties (JENKINS-17523)
-
If a Gradle Build Scan is produced during the build then a link is added to the build page.
-
Fix JENKINS-18629 - Jenkins fails to save configuration when using Invoke Gradle script in Conditional Step (single).
-
Fix issue #17386 - Gradle.properties ignored after 1.22 upgrade. GRADLE_USER_HOME is now no longer set to the workspace of the job by default. If you wish to have the workspace job as the GRADLE_USER_HOME, you will need to change the config to reflect this.
-
Fix JENKINS-17294 - mask sensitive variables (Password parameters)
-
Fix JENKINS-13412 - use hudson.util.ArgumentListBuilder#toWindowsCommand
-
Set GRADLE_USER_HOME all the time
-
Add the ability to allow gradlew to still be run from workspace top, but to also configure it so that gradlew is found in the root build script directory.
-
Fix JENKINS-12769 - Cannot specify location of gradle wrapper
-
Fix JENKINS-15406 - When using gradlew, root build script field is not used to locate gradlew
-
Fix JENKINS-15166 - Gradle plugin fails to save selected Gradle Version in Project configuration
-
Merge pull request - Change Gradle Wrapper logic to use the launcher’s OS type rather than master’s OS type when determining Gradle Wrapper script name
-
Fix reopened JENKINS-9538 - hudson.model.FreeStyleBuild & GradleInstallation not serializable ⇒ Gradle build not working anymore
-
Fix reopened JENKINS-13412 - Gradle plugin fails to quote parameters without whitespace when containing input/output redirection symbols, e.g. in XML strings
-
Fix JENKINS-13412 - Gradle plugin fails to quote parameters without whitespace when containing input/output redirection symbols, e.g. in XML strings
-
Fix JENKINS-9538 - hudson.model.FreeStyleBuild & GradleInstallation not serializable ⇒ Gradle build not working anymore
-
Coloring output log and Navigation executed tasks (from pull request of ikikko)
-
Update to Jenkins 1.397 API and metadata
-
Change UI labels from Hudson to Jenkins
-
Fix help messages
-
Add technical internal behavior for a suitable Artifactory/Gradle integration (with the buildinfo)
-
Add a description message in the build step
-
The plugin makes it possible to extract a Gradle distribution from a shared location or from a command line, and uses this distribution for running the build.
-
Add a distinction between switches and tasks
-
The plugin makes its possible to specify the location of the build script if the workspace has a top-level build.gradle in somewhere other than the module root directory
-
Improve user help messages
-
Add the support of Gradle 0.5. Before the version 0.5, the gradle windows executable file was "gradle.exe", and you lost the ERRORLEVEL value. From Gradle 0.5, the window launcher is a .bat file that conserves the correct ERRORLEVEL value.