Reputation: 215
I am trying to do following steps:
I have a build.gradle
file configured for my project. I want to execute the currentVersion task for my project to get the current version that the build generated and then save it to a text file. I wil
l run this build using jenkins and use that text file to get the version number to download the correct artifact from Nexus Repository.
I feel either of the below ways can help me achieve this:
Upvotes: 5
Views: 5576
Reputation: 47259
If you want to make use of task input/output caching you could do something like the following in your build.gradle
:
tasks.create('currentVersion') {
outputs.file('versionFile.txt')
inputs.property('version', project.version)
doLast {
project.file('versionFile.txt') << project.version
}
}
Then, you can run the task like ./gradlew currentVersion
and the output will go to the file that you want to write to. Next time you run the task, the file will only be updated if the inputs or outputs change.
Upvotes: 5
Reputation: 215
In Jenkins, I added Execute Shell. Within execute shell, I can run gradle tasks like this.
./gradlew currentVersion > bbc.txt
This way I got the task output in a file.
Upvotes: 0