Powershell - upload file to Nexus Repo Manager
I preferred solution 3 listed on devops schools because it builds on other TILs I alread have, such as Powershell - basic auth in Authorization header
The tricky part was using the InFile
option.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# prepare basic auth credentials
$user = "User"
$password = "S3cr3t"
$pair = "$($user):$($password)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
$NexusUrl = "https://nexus.uri.com"
$Repository = "my-raw-repo"
$AssetGroupName = "/path/to/app/v1.0.3"
$file = "myapp.zip"
$Uri = "$NexusUrl/repository/$Repository/$file"
Invoke-RestMethod -UseBasicParsing -Headers $headers -Method PUT -InFile $file -Uri $Uri
This post is licensed under CC BY 4.0 by the author.