Skip to content

Instantly share code, notes, and snippets.

@kellyrob99
Last active March 15, 2022 08:44
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kellyrob99/2d1483828c5de0e41732327ded3ab224 to your computer and use it in GitHub Desktop.
Save kellyrob99/2d1483828c5de0e41732327ded3ab224 to your computer and use it in GitHub Desktop.
List all assets in a given repository that have been updated after a specific time
import org.sonatype.nexus.repository.storage.Asset
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def request = new JsonSlurper().parseText(args)
assert request.repoName: 'repoName parameter is required'
assert request.startDate: 'startDate parameter is required, format: yyyy-mm-dd'
log.info("Gathering Asset list for repository: ${request.repoName} as of startDate: ${request.startDate}")
def repo = repository.repositoryManager.get(request.repoName)
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
tx.begin()
Iterable<Asset> assets = tx.
findAssets(Query.builder().where('last_updated > ').param(request.startDate).build(), [repo])
def urls = assets.collect { "/repository/${repo.name}/${it.name()}" }
tx.commit()
def result = JsonOutput.toJson([
assets : urls,
since : request.startDate,
repoName: request.repoName
])
return result
@Profyy
Copy link

Profyy commented Apr 25, 2017

Hi,

what is the right format to define 'startDate' ?

Best regards,
Hristo

@kellyrob99
Copy link
Author

@Profyy Sorry for the late response, updated the script to include the expected Date format

@HerrmannHinz
Copy link

would be nice to have valid json in the response. the "assets" is an escaped string. bit hard to parse with jq for example.

@chuieng
Copy link

chuieng commented Aug 31, 2017

how to run this?

@srikanthrlinux
Copy link

Can we get list of all artifacts with this scripts?

@jaekunchoi
Copy link

how to get list in date descending order?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment