Hopefully this is not a repeat question, but, being new to Gradle, I’m looking for guidance to either documentation and/or an example/tutorial that is beyond the standard “Hello, World” search results I keep finding.
I am interested in creating a plug-in for use in our CI system. The basic idea is to be able to retrieve build artifacts from our Jenkins server using a simple DSL syntax in a Gradle build file. For example,
apply plugin: 'jenkins-artifact'
jenkinsArtifact {
// URL of the Jenkins server
siteUrl = 'https://jenkins.server.net/'
// Private RSA key to be used when connecting to the Jenkins CLI
rsaKey = file('resources/id_rsa_JENKINS')
// Where we are going to store the artifacts once downloaded;
// ${outputDir}/${job}/${artifactRelativePath}
outputDir = file("${buildDir}/jenkins-artifacts")
// One or more build artifacts, each described by the name of the
// job that creates them, the particular build of that job, and a
// regex pattern used to identify the item(s) to retrieve
artifact [ job: 'Build_AppA', build: '42', namePattern: 'appA-(debug|release)\.apk$' ]
artifact [ job: 'Build_AppB', build: 'lastSuccessfulBuild', namePattern: 'appB\.apk$' ]
}
The design is still rudimentary, and I am open to suggestions as to best practices. Thus far, I have a very basic skeleton laid out that includes the plugin (JenkinsArtifactPlugin
), a download task (JenkinsArtifactDownloadTask
) for doing the actual retrieval of the build artifact(s), and an extension/configuration class for the jenkinsArtifact
block (JenkinsArtifactExtension
), sans the artifact
entries:
class JenkinsArtifactExtension {
@Input
def String siteUrl
@InputFile
def File rsaKey
@OutputDirectory
def File outputDir = new File("${project.buildDir}/jenkins-artifacts")
//
// artifacts??
//
}
This is where I am presently blocked looking for the correct way to do the artifacts. I’ve Googled, checked Stackoverflow, went looking for books on Amazon, and I can’t seem to find something that gives decent guidance on how to implement this.
These are essentially dependencies for the build script, so should this be implemented using a configuration instead? Something like:
configurations {
jenkinsArtifact
}
dependencies {
jenkinsArtifact // ... what to put here since these are not described by GAV ...
}
Or is my initial sketch preferred? And, if so, what classes should I use to implement it?
The end result should be something I can query as part of the plug-in to create a JenkinsArtifactDownloadTask
instance for each requested build artifact.
Any and all help is greatly appreciated. Thanks in advance,
– William