🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to download package from Nexus using curl?

$URL = "http://nexusrepo/nexus/service/local/artifact/maven/redirect?r=my-snapshot&g=my.group.id&a=my.artifact.id&v=1.10.0-SNAPSHOT&c=win32.win32.x86_64&p=zip"
$username = "nexus"
$password = "nexus"
$auth=$username+":"+$password
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)
$latestArtifactURL = Invoke-WebRequest $url -Headers @{Authorization = "Basic $EncodedPassword"} -MaximumRedirection 0
$redirectedMessage = "$latestArtifactURL".IndexOf('http:')
$targetURL = "$latestArtifactURL".SubString("$redirectedMessage")
Invoke-WebRequest $targetURL -Headers @{Authorization = "Basic $EncodedPassword"} -OutFile "MyApp.zip"
$ curl -sSL -X GET -G "http://mynexus3.local/service/rest/v1/search/assets" \
-d repository=maven-snapshots \
-d maven.groupId=my.group.id \
-d maven.artifactId=my-artifact \
-d maven.baseVersion=1.0-SNAPSHOT \
-d maven.extension=jar \
-d maven.classifier=jar-with-dependencies \
| grep -Po '"downloadUrl" : "\K.+(?=",)' \
| xargs curl -fsSL -o my-artifact.jar
# Download entire repository from Nexus 3.37.1
sourceServer=
sourceRepo=
sourceUser=
sourcePassword=
logfile=$sourceRepo-backup.log
outputFile=$sourceRepo-artifacts.txt
# ======== GET DOWNLOAD URLs =========
url=$sourceServer"/service/rest/v1/assets?repository="$sourceRepo
contToken="initial"
while [ ! -z "$contToken" ]; do
if [ "$contToken" != "initial" ]; then
url=$sourceServer"/service/rest/v1/assets?continuationToken="$contToken"&repository="$sourceRepo
fi
echo Processing repository token: $contToken | tee -a $logfile
response=`curl -ksSL -u "$sourceUser:$sourcePassword" -X GET --header 'Accept: application/json' "$url"`
readarray -t artifacts < <( jq '[.items[].downloadUrl]' <<< "$response" )
printf "%s\n" "${artifacts[@]}" > artifacts.temp
sed 's/\"//g' artifacts.temp > artifacts1.temp
sed 's/,//g' artifacts1.temp > artifacts.temp
sed 's/[][]//g' artifacts.temp > artifacts1.temp
cat artifacts1.temp >> $outputFile
#for filter in "${filters[@]}"; do
# cat artifacts.temp | grep "$filter" >> $outputFile
#done
#cat maven-public-artifacts.txt
contToken=( $(echo $response | sed -n 's|.*"continuationToken" : "\([^"]*\)".*|\1|p') )
done
# ======== DOWNLOAD EVERYTHING =========
echo Downloading artifacts...
urls=($(cat $outputFile)) > /dev/null 2>&1
for url in "${urls[@]}"; do
path=${url#http://*:*/*/*/}
dir=$sourceRepo"/"${path%/*}
mkdir -p $dir
cd $dir
pwd
curl -vks -u "$sourceUser:$sourcePassword" -D response.header -X GET "$url" -O >> /dev/null 2>&1
responseCode=`cat response.header | sed -n '1p' | cut -d' ' -f2`
if [ "$responseCode" == "200" ]; then
echo Successfully downloaded artifact: $url
else
echo ERROR: Failed to download artifact: $url with error code: $responseCode
fi
rm response.header > /dev/null 2>&1
cd $curFolder
done
curl -X 'POST' \
'http://<SERVER_IP_ADDRESS>:<PORT_NUMBER>/service/rest/v1/components?repository=<REPO_NAME>' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Basic <NEXUSCRED>' \
-F 'raw.directory=<DIR_NAME>' \
-F 'raw.asset1=@<FILE_NAME>.zip;type=application/x-zip-compressed' \
-F 'raw.asset1.filename=<FILE_NAME>.zip'
curl -X 'POST' \
'http://localhost:8082/service/rest/v1/components?repository=devopsrepo' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-F 'raw.directory=devops ' \
-F 'raw.asset1=@C:\Nexus\devops-1.0.0.0.zip;type=application/x-zip-compressed' \
-F 'raw.asset1.filename=devops-1.0.0.0.zip'
curl -O --output-dir /some-dir http://<SERVER_IP_ADDRESS>:<PORT_NUMBER>/repository/<REPO_NAME>/<DIR_NAME>/<FILE_NAME>.zip
curl -O --output-dir C:/Nexus/package http://localhost:8082/repository/devopsrepo/devops/devops-1.0.0.0.zip
curl -L -X GET 'https://MY_NEXUS/service/rest/v1/search/assets/download?sort=version&repository=MY-REPO&group=MY_GROUP&name=MY_ARTIFACT_NAME&maven.baseVersion=0.1-SNAPSHOT' --output some.file
# Getting the name of the latest artifact in a raw nexus repository
curl -L -X GET "nexus-url/service/rest/v1/search/assets/?sort=version&repository=management&group=rpms.test"
wget --user=username --password=password "http://<ip>:<port>/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>&v=<version>&r=snapshots"
wget --user=userid --password=password 'https://nexusurl:8081/nexus/repository/<repository id>/<replace the grouf is . with />/<artifact id>/<version>/<file name>' -O ${WORKSPACE}/<new file name>
wget --http-user myusername --http-password=mypassword https://nexus.example.com/myfile.zip
view raw wget.sh hosted with ❤ by GitHub
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x