I have recently switched from Maven to Gradle. So far my Jenkins declarative pipelines included a stage where we generated the packaged artifact and published it to Nexus:
pipeline {
...
stages {
stage ('Build Stage') {
steps {
...
sh "mvn clean deploy"
...
}
}
This way we were using our build tool (Maven) to deploy the artifact using one of its plugins (maven deploy plugin). With Nexus Jenkins Plugin we can decouple these functionalities which makes sense to me: Gradle is in charge of building, testing and packaging the artifact and the Jenkins Nexus Plugin will upload it to Nexus.
The point is, following Jenkins Nexus Plugin documentation I have to use a step like the following:
nexusPublisher nexusInstanceId: 'localNexus', nexusRepositoryId: 'releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: 'buildmavenCoordinate: [artifactId: 'myproject'/lib/myproject-1.0.0.jar']], , groupId: 'com.codependent.myproject', packaging: 'jar', version: '1.0.0']]]
Since I want to produce a resusable pipeline, I don't want to hardcode the following properties in the step:
- groupId
- artifactId
- packaging
- version
If I were working with Maven I would use the readMavenPom step from the Pipeline Utility steps plugin to pass them to the nexusPublisher step:
def pom = readMavenPom file: 'pom.xml'
...
nexusPublisher ... mavenCoordinate: [artifactId: pom.artifactId
...
My problem is how to get those four parameters from Gradle configuration in the pipeline.
Suppose my build.gradle is as follows:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
group = 'com.codependent.myproject'
version = '1.0.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
...