I try download artifact from Jenkins using PowerShell, like this:
$webClient = new-object System.Net.WebClient
$webClient.Credentials = New-Object System.Net.NetworkCredential ("username", "password")
$url = "http://jenkins/job/jobName/lastSuccessfulBuild/artifact/*zip*/archive.zip"
$localfilename = "C:\Test\archive.zip"
$webClient.DownloadFile($url, $localfilename)
I get exception:
Exception calling "DownloadFile" with "2" argument(s): "The remote server retur ned an error: (403) Forbidden." At C:\ps2.ps1:20 char:28 + $webclient.DownloadFile <<<< ($url, $localfilename) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
If I try download artifact using wget it works:
wget --auth-no-challenge --http-user=username --http-password=password http://jenkins/job/jobName/lastSuccessfulBuild/artifact/*zip*/archive.zip
If I using wget without parameter --auth-no-challenge
I get the same error - Forbidden
.
Jenkins PowerShell PluginIntegrates with PowerShell by allowing you to directly write PowerShell scripts into the text box in Jenkins. Other than that, this plugin works pretty much like the standard shell script support.
Using this authorization in request header is working great:
# Create web client with authorization header
$webClient = new-object System.Net.WebClient
$credentialAsBytes = [System.Text.Encoding]::ASCII.GetBytes($userName + ":" + $password)
$credentialAsBase64String = [System.Convert]::ToBase64String($credentialAsBytes);
$webClient.Headers[[System.Net.HttpRequestHeader]::Authorization] = "Basic " + $credentialAsBase64String;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With