Skip to content

Commit

Permalink
Update nexusSync.groovy
Browse files Browse the repository at this point in the history
Change Nexus API Path
Add  New parameter (Target Nexus id, password)
  • Loading branch information
jaekwonpark-flo authored Aug 12, 2020
1 parent cdefab5 commit 2627856
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions nexusSync.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import static groovyx.net.http.ContentType.*

def printUsage(){
println """Usage:
groovy nexusSync.groovy [type] [sourceUrl] [toUrl]
groovy nexusSync.groovy [type] [sourceUrl] [toUrl] [TargetNexusID] [TargetNexusPass]
type: maven or npm
sourceUrl: sync source. must end with '/'
toUrl: sync target. must end with '/'
type: maven or npm
sourceUrl: sync source. must end with '/'
toUrl: sync target. must end with '/'
TargetNexusID: traget Nexus ID Default admin. Optional
TargetNexusPass: traget Nexus ID Default admin. Optional
Example:
groovy nexusSync.groovy maven http://localhost:8081/nexus/maven-public/ http://my-private-nexus.com/nexus/private_repository/
groovy nexusSync.groovy maven http://localhost:8081/nexus/maven-public/ http://my-private-nexus.com/nexus/private_repository/ admin admin123
"""
}

Expand All @@ -35,6 +38,23 @@ def isValidUrl(url) {

def sourceFullUrl = args[1];
def targetFullUrl = args[2];
def nexusID = args [3];
def nexusPass = args [4];

if (nexusID) {
println "Traget Nexus id ${nexusID}"
} else {
println "Traget Nexus id admin"
def nexusID = admin
}

if (nexusPass) {
println "Traget Nexus Pass ${nexusPass}"
} else {
println "Traget Nexus Pass admin123"
def nexusPass = admin123
}


if (sourceFullUrl == targetFullUrl || ! isValidUrl(sourceFullUrl) || ! isValidUrl(targetFullUrl)){
println "Invalid url"
Expand Down Expand Up @@ -66,7 +86,7 @@ def fetch = { url, repository->
def restClient = new RESTClient(url)
def continuationToken = null ;
def items = []
def path = "${context}/service/rest/beta/assets".replace('//','/').replace('//','/').replace('//','/')
def path = "${context}/service/rest/v1/assets".replace('//','/').replace('//','/').replace('//','/')

while(true) {
def query = ['repository':repository]
Expand Down Expand Up @@ -140,7 +160,7 @@ repositories.each { repository ->
def rightPath = "/repository/${repository.to}/"

def uploadUrl = "${rightUrl}/${rightPath[1..-1]}${subpath}"
def uploadCmd = "curl -v -u admin:admin123 --upload-file ${fileName} ${uploadUrl}"
def uploadCmd = "curl -v -u ${nexusID}:${nexusPass} --upload-file ${fileName} ${uploadUrl}"
println uploadCmd
println uploadCmd.execute().text
}
Expand Down

0 comments on commit 2627856

Please sign in to comment.