maven - Jenkins build parameterized with a choice of versions of a Nexus artifact (all GAVs) -
is there jenkins plugin can group-artifact-version (gav) search of nexus repo , list results? results available on parameterized build choice (a dropdown).
i added groovy script dynamic choice parameter (see jenkins plugins)
some hurdles were:
- our nexus server issues basic authentication challenge couldn't use groovy "http://blah".tourl().text
- i didn't want load in missing groovy jars httpbuilder used java urlconnection class , encoded user:pass header.
- used rest api nexus versions, had distinguish between release , snapshots. added group based authentication developers had access snapshots.
- gav sort not straight forward. there better way gav sort (using org.apache.maven.artifact.versioning.comparableversion) have not implemented yet now, i'm sorting smaller strings line first.
import hudson.model.* import jenkins.model.* def versions=[ ] def snapshots=[ ] // artifactname passed in parameter (eg. extended choice parameter) linked 'dynamic choice' parameter. def address = "https://xyzcompany.com/nexus/service/local/lucene/search?r=releases&g=com.xyzcompany&a=artifactname&c=features&p=xml" def urlinfo = address.tourl() // consider using tokenstring technique instead of basic auth if pro version of nexus. def authstring = "user:pass"; // replace 'user' username, 'pass' password. def authstr="basic " + authstring.bytes.encodebase64().tostring() // using urlconnection instead of httpbuilder et al. def connection = urlinfo.openconnection() connection.setrequestproperty( "authorization" , authstr) def xml="${connection.content.text}" def root = new xmlparser().parsetext( xml ) root.data.artifact.each { if (it.artifacthits.artifacthit.repositoryid.text() == "releases") versions.add("${it.version.text()}"); else snapshots.add("${it.version.text()}"); } // there better way gav sort (using org.apache.maven.artifact.versioning.comparableversion) have not implemented yet now, i'm sorting smaller strings line first. versions.sort { -it.size() } collections.reverse(versions) // users should able see snapshot versions def userid = user.current().id def auths = jenkins.instance.securityrealm.loaduserbyusername(userid).authorities.collect{a -> a.authority} if (["offshoredevgroup", "devgroup"].intersect(auths)) { snapshots.sort { -it.size() } collections.reverse(snapshots) versions+=snapshots } versions.add(" "); // build uses blank version string report deployed container. return versions;
Comments
Post a Comment