Define your Sonatype Nexus repository structure as code. This script defaults to interact with a nexus server running on localhost.
$ nexus-claim plan -i input.hcl -o output.json
$ nexus-claim apply -i output.json
If in case of doubt, issue nexus-claim --help
to get going.
--server value, -s value Url to the nexus server (default: "http://localhost:8081") [$NEXUS_SERVER]
--username value, -u value Username of a nexus admin user (default: "admin") [$NEXUS_USER]
--password value, -p value Password of the nexus user (default: "admin123") [$NEXUS_PASSWORD]
--nexus2 use this flag to use nexus-claim with nexus 2 [$NEXUS_V2]
--help, -h show help
--version, -v print the version
- Have a decent version of Golang installed
- Install Golang dependencies with
go mod vendor && go mod tidy
- Build the software in the
target/
directorymake clean && make
- Start up a local nexus
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
- Access docker container and extract admin password
docker exec -it nexus sh
thancat /nexus-data/admin.password
- Plan a custom repository
.hcl
filetarget/nexus-claim --password "<password>" plan -i resources/nexus3/nexus_custom_example.hcl -o targetState.json
- this reads existing repositories from the nexus, changes from the given
.hcl
file will make up the target state as JSON - the target state is supposed to be created within the nexus-claim application
- Apply target state
.json
file to nexus- an auto-generated
.groovy
file responsible for interacting with the nexus API in terms of creating will be uploaded in the nexus. - the
.groovy file
responsible for creation will be called with the target.json
being the argument
- an auto-generated
- The repository changes are being written. Check the nexus frontend for changes.
- on maven2-hosted- and maven2-proxy-repository there must be a maven sector in addition(with versionPolicy and writePolicy)
- Note the autogenerated
.groovy
files are only an interaction layer and should not contain larger application logic
Examples can be found in the nexus 3 resources directory. Also available in the same directory are resulting target .json
files for reference.
Examples can be found in the nexus 2 resources directory