Last active
December 3, 2024 10:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
how to run this?
Can we get list of all artifacts with this scripts?
how to get list in date descending order?
No longer working on 3.71
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would be nice to have valid json in the response. the "assets" is an escaped string. bit hard to parse with jq for example.