1
votes

I managed to publish my artifacts by using Gradle into Artifactory. But the version is always unspecified (example-unspecified.jar)

How Can set groupId ="com.example" and version 'BUILD_NUMBER' into jenkins??

I want to publish something like that example-10.jar (10 is Jenkins build number, and group: 'com.example')

Thanks

2

2 Answers

2
votes

You need to set the group and version in the build.gradle

apply plugin: "java"

group = 'com.company.blah'
version = project.hasProperty('build_number') ? project.properties['build_number'] : '0.1'

Then the build will produce artifacts like "$project.name-${project.version}.jar"

The group is used by maven to organize the artifacts and is the first item in dependency notation "$project.group:$project.name:$project.version"

So if we build without any params it will produce blah-0.1.jar If we build with the param build_number it will assign the version supplied.

For example: gradlew clean build -Pbuild_number=10 will produce blah-10.jar

1
votes

BUILD_NUMBER is populated via environment variables by Jenkins. If you want to get access to it from Gradle script, you can do it as follows:

def buildNumber = System.getenv("BUILD_NUMBER")

And then use buildNumber variable in your artifactory publish code.

As for groupId, I don't really understand what's the problem there.. It doesn't change during Jenkins build, does it? So you can just hardcode it inside your gradle script.

As an alternative, you can pass necessary information via project properties:

./gradlew assemble -PgroupId=com.example -PbuildNumber=$BUILD_NUMBER