0
votes

I'm trying to download XML file (Jenkins config.xml history file) from Jenkins HTTPS server. I searched here and elsewhere but still cannot find the way to get it working.

$url = "https://<server-path>/configOutput?type=xml&timestamp=2018-02-23_13-09-02"

$file = "d:\file.xml"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3
$wc = New-Object System.Net.WebClient
$wc.Credentials = Get-Credential
$wc.DownloadFile($url, $file)

After supplying credentials to prompt I'm getting this error:

Exception calling "DownloadFile" with "2" argument(s): "The underlying connection
was closed: An unexpected error occurred on a receive."
At D:\ps\jenkins-config\get_xml.ps1:7 char:1
+ $wc.DownloadFile($url,$file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException
1
I don't see anything wrong with your code (other than SSLv3 being broken), so the issue is probably with the network or the server. Check the Jenkins logs.Ansgar Wiechers
Ok, so it seems that the problem is with log in. Jenkins expects logged in user and even though I supply correct credentials the information about successful login is not saved anywhere (session, cookie, ..) therefore I am still getting 403. So the problem here is to first log in (in PS script), save this info and then request the page from URL. Is this even possible?himi

1 Answers

0
votes

I'd use the Invoke-WebRequest method:

Invoke-WebRequest -Uri $url -ContentType 'application/xml' -OutFile $file -Credential $(Get-Credential) -Timeout 60

I've seen "configOutput" for job history care-of the JobConfigHistory plug-in. I've never seen it to get Jenkin's config file (the one in JENKINS_HOME). If you're trying to control a job's config, double check your URL.