Skip to content

Instantly share code, notes, and snippets.

@nblair
nblair / blobstore-script.diff
Last active December 20, 2019 16:30
3.19 vs 3.20 BlobStoreConfiguration use within Groovy API
diff --git a/system-under-test/post-install-scenarios/01_blobstore.groovy b/system-under-test/post-install-scenarios/01_blobstore.groovy
index ea8db9d..9dbf852 100644
--- a/system-under-test/post-install-scenarios/01_blobstore.groovy
+++ b/system-under-test/post-install-scenarios/01_blobstore.groovy
@@ -1,14 +1,15 @@
-import org.sonatype.nexus.blobstore.api.BlobStoreConfiguration
import org.sonatype.nexus.blobstore.api.BlobStoreManager
import groovy.json.JsonSlurper
def object = new JsonSlurper().parseText(args)
@nblair
nblair / create_blobstore.groovy
Created February 7, 2019 17:47
Create a Google Cloud Blobstore with the Nexus Repository Manager Script API
import org.sonatype.nexus.blobstore.api.BlobStoreConfiguration
import org.sonatype.nexus.blobstore.api.BlobStoreManager
def blobStoreManager = container.lookup(BlobStoreManager.class.name)
blobStoreManager.create(new BlobStoreConfiguration(name: 'default', type: 'Google Cloud Storage',
attributes: [
'google cloud storage': [
bucket: "bucket-name-goes-here" // if you use an interpolated Groovy String here, make sure you call toString()
]
]))
@nblair
nblair / nexus-check-orientdb-freeze-state.groovy
Created October 12, 2017 20:47
A groovy script to check the 'freeze' state of Nexus Repository Manager databases
/**
* Tested with Nexus Repository Manager 3.6.
* Warning: uses internal APIs which are subject to change.
*
* When run, prints a task log entry for each OrientDB database indicating whether or not the database is frozen.
* See https://orientdb.com/docs/2.2/Console-Command-Freeze-Db.html
*
* Usage:
* 1. Create a task with the "Execute Script" type - see https://help.sonatype.com/display/NXRM3/Configuration#Configuration-ConfiguringandExecutingTasks
* 2. Set task frequency to manual
@nblair
nblair / create-proxy-repository.groovy
Created July 18, 2017 11:02
Nexus Repository Manager 3 script for creating a proxy repository of an upstream that requires HTTP authentication.
def configuration = new org.sonatype.nexus.repository.config.Configuration()
configuration.setAttributes(
'maven': [
'versionPolicy': 'RELEASE',
'layoutPolicy': 'STRICT'
],
'proxy': [
'remoteUrl': 'http://localhost:8000',
'contentMaxAge': -1,
'metadataMaxAge': 1440
@nblair
nblair / nexus-repo-manager-privilege-example.groovy
Last active November 13, 2023 17:54
A groovy script to create Content Selectors, privileges, and roles programmatically via the Nexus Repository Manager 3 Scripting API.
import org.sonatype.nexus.common.entity.*
import org.sonatype.nexus.security.*
import org.sonatype.nexus.security.authz.*
import org.sonatype.nexus.selector.*
import com.google.common.collect.ImmutableMap
// use container.lookup to fetch internal APIs we need to use
def selectorManager = container.lookup(SelectorManager.class.name)
def securitySystem = container.lookup(SecuritySystem.class.name)
@nblair
nblair / RecordedSimulation.scala
Created May 24, 2017 14:46
Sample gatling recorded simulation
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class RecordedSimulation extends Simulation {
val httpProtocol = http
@nblair
nblair / artifact-version-yaml.groovy
Created October 17, 2016 15:51
Groovy script to help Jenkins identify the version of the artifact it just built.
/**
* Reads the version of the artifact from the Spring Boot application.yml.
* Depends on the following in build.gradle:
<pre>
processResources {
filesMatching('application.yml') {
expand(project.properties)
}
}
</pre>
@nblair
nblair / artifact-version.groovy
Last active October 17, 2016 15:23
Groovy script to help Jenkins identify the version of the artifact it just built.
/**
* Reads the version of the artifact from the MANIFEST.
* Depends on actually setting version in MANIFEST; Gradle snippet below:
<pre>
jar {
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.version
)
plugins {
id 'com.craigburke.bower-installer' version '2.5.1'
}
bower {
installBase = 'src/main/resources/static/bower_components'
// any changes to bower dependencies must also be manually copied to src/main/resources/bower.json
'angular'('~1.5.5') {
source 'angular.min.js'
}
'angular-animate'('~1.5.5') {
@nblair
nblair / build.gradle
Created July 13, 2016 16:53
Gradle task to assist in release management, to be paired with: https://gist.github.com/nblair/53f44e08104354dd078e6104d7dae4a8
/**
* Task executed by Jenkins on merges to master to confirm that we appropriately track the last
* released version.
* Typical commands executed by this Jenkins job, in order:
* 1. gradlew clean updateProjectLast
* 2. git commit -am "Tracking last released version"
* 3. gradlew bootRepackage uploadArchives
*/
task updateProjectLast() {
doLast {