Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bitbucket Pipelines: Gradle change file while building

Patrick Farwick January 12, 2017

Hi,

I'm wondering how I can change the version number of my project with each build from gradle using Bitbucket Pipelines. 

I'm currently having a build.properties file which includes some version numbers and I've got this code in my build.gradle (all files, including the build.properties, build.gradle, gradle wrapper.jar and all the gradle scripts under 'apply from' are uploaded to the repository):

 

task wrapper(type: Wrapper) {
	gradleVersion = '3.3'
}

// define the properties file
ext.configFile = file "build.properties"

configFile.withReader {
	if(configFile.canRead()) {
	    // read config.
		def Properties prop = new Properties()
		prop.load(it)
		
			
	def jae_build = prop['jae_build'].toInteger() + 1
	prop['jae_build'] = jae_build.toString()
	
	prop.store(configFile.newWriter(), null)
	
	ext.config = new ConfigSlurper().parse prop
	} else {
		throw new GradleException("Could not read build.properties!")
	}
}

apply from: 'gradle/scripts/dependencies.gradle'
apply from: 'gradle/scripts/artifacts.gradle'
apply from: 'gradle/scripts/optional.gradle'

 

My Bitbucket-pipelines.yml:

image: java:8

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - bash ./gradlew --version
          - bash ./gradlew build

 

So, building the code is working fine, but my gradle script does not change the build number

jae_build

in my build.properties file. This occurs only using Bitbucket pipelines. Building it with the same commands manually on my Windows 10 systems results into the change of the build number, like I want it to happen. wink

 

Any idea how to let Bitbucket pipelines change my build number in the build.properties file using gradle? (should also work locally on windows smile

Thx in advance.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
SebC
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2017
TAGS
AUG Leaders

Atlassian Community Events