Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Profyy Profyy commented Apr 25, 2017

Hi,

what is the right format to define 'startDate' ?

Best regards,
Hristo

@kellyrob99

This comment has been minimized.

Copy link
Owner Author

@kellyrob99 kellyrob99 commented Jun 21, 2017

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

@HerrmannHinz

This comment has been minimized.

Copy link

@HerrmannHinz HerrmannHinz commented Jul 4, 2017

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

This comment has been minimized.

Copy link

@chuieng chuieng commented Aug 31, 2017

how to run this?

@srikanthrlinux

This comment has been minimized.

Copy link

@srikanthrlinux srikanthrlinux commented Sep 19, 2017

Can we get list of all artifacts with this scripts?

@jaekunchoi

This comment has been minimized.

Copy link

@jaekunchoi jaekunchoi commented Mar 6, 2018

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
You can’t perform that action at this time.