Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to upload package to Nexus and Artifactory using curl and powershell?

Solution – 1


$URI = New-Object System.Uri("https://artifactory.example.com/artifactory/net-generic-local/APP/BF_2.0.zip")  
$SOURCE = ".\BF_2.0.zip"  
$AF_USER = "user"  
$AF_PWD = ConvertTo-SecureString "password" -AsPlainText -Force  
$CREDS = New-Object System.Management.Automation.PSCredential ($AF_USER, $AF_PWD)  

Invoke-WebRequest -Uri $URI -InFile $SOURCE -Method Put -Credential $CREDS  

Solution – 2


$SOURCE = ".\BF_2.0.zip"  
$DESTINATION = "https://artifactory.example.com/artifactory/net-generic-local/APP/BF_2.0.zip"  
$AF_USER ="user"  
$AF_PWD ="password"  
$WebClient = New-Object System.Net.WebClient  
$WebClient.Credentials = New-Object System.Net.NetworkCredential($AF_USER, $AF_PWD)  
$URI = New-Object System.Uri($DESTINATION)
$METHOD = "PUT"  
$WebClient.UploadFile($URI, $METHOD, $SOURCE) 

Solution – 3


$credential_bytes = [System.Text.Encoding]::UTF8.GetBytes($username + ":" + $api_token)
$credentials = [System.Convert]::ToBase64String($credential_bytes)
$credential_header = "Basic " + $credentials    
Invoke-WebRequest -Uri $artifactory_dest_url -InFile "my_file.zip" -Method Put -Headers @{"Authorization"="$credential_header"}

Solution – 4


$SOURCE = ('D:\RefreshAutomationProd_bkp' + (get-date -Format yyyyMMdd) + '.zip')
echo "SOURCE : $SOURCE"

$DESTINATION = "http://172.26.10.46:8081/repository/RefreshAutomation/"+('RefreshAutomationProd_bkp' + (get-date -Format yyyyMMdd) + '.zip')
echo "DESTINATION : $DESTINATION"  

$AF_USER ="admin"  
$AF_PWD ="Admin@123"  
$WebClient = New-Object System.Net.WebClient  
$WebClient.Credentials = New-Object System.Net.NetworkCredential($AF_USER, $AF_PWD)  
$URI = New-Object System.Uri($DESTINATION)
$METHOD = "PUT"  
$WebClient.UploadFile($URI, $METHOD, $SOURCE)

Rajesh Kumar
Follow me
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x