15

Where should I put the gradle.properties file in Jenkins?

I'm using version 1.21 of the Gradle plugin, but it isn't finding the properties file when I put it in the user home .gradle directory.

Any pointers would be much appreciated.

Thanks

UPDATED

The Gradle plugin looks by default in the workspace of each project for a gradle.properties file. In order to use one file across all jobs, you need to set your gradle home in your job configurations as follows, by adding the following under 'switches':

-Dgradle.user.home=$HOME/.gradle
user1740752
  • 543
  • 1
  • 4
  • 13

5 Answers5

25

The Gradle plugin looks by default in the workspace of each project for a gradle.properties file. In order to use one file across all jobs, you need to set your gradle home in your job configurations as follows, by adding the following under 'switches':

-Dgradle.user.home=$HOME/.gradle
user1740752
  • 543
  • 1
  • 4
  • 13
  • +1 from me! However, I'm using different nodes with different user-homes, so I configured it like -Dgradle.user.home=${GRADLE_USER_HOME} and defined the environment variable with value 'C:\Users\\.gradle' in the configuration of each node. Hope it'll help someone with similar situation as me. – P Kuijpers May 14 '18 at 14:48
4

In your Jenkins webpage, you can see 'user.home' property in 'System Information' page. (for slve, check slave's 'System Information' page) You'd put gradle.properties under 'user.home'/.gradle/ folder and every gradle job could see that properties. Adding switch is not work if your job runs on the other slave environment (ie. Windows system)

devmojopum
  • 41
  • 1
2

In addition to the answer of @devmojopum, make sure "Force GRADLE_USER_HOME to use workspace" is not checked in your job configuration.

Gradle Configuration

user2880229
  • 151
  • 8
0

I do not agree with the upvoted answers. This only works in single-workspace environments. If you use multiple projects, have multiple nexus environments to publish to,and want also e.g. jenkins not to mess up, then you should read

https://docs.gradle.org/current/userguide/build_environment.html

how to chain gradle properties.

Gradle project properties can be stored in a separate folder and copied to the workplace root, the latter one added to .gitignore, so everybody can configure her own passwords and settings.

This also encourages to use the FORCE flag to be uses in Jenkins.

-6

Just put gradle.properties next to your build.gradle.

Regards, Olle

Olle Hallin
  • 588
  • 1
  • 3
  • 12