I'm trying to set up a Chef recipe to install and manage a Jenkins server. So far I can get the server installed and manage it's config so that it listens on port 80.
My problem right now is that I can't get it to scripts it's way through the initial administrator password so I can actually access the server.
So far I have the script blow that can find the password and submit the web page back to Jenkins, but Jenkins always claims the password is incorrect.
Is there any easier way to get this done than scraping Jenkins' web pages? Maybe a way to avoid this password screen after install entirely?
Thanks,
Bill
$hostName = $env:computername
if(-not (Test-Path 'C:/Program Files (x86)/Jenkins/secrets/initialAdminPassword'))
{
exit -1
} else {
$password = Get-Content 'C:/Program Files (x86)/Jenkins/secrets/initialAdminPassword'
}
$loginPage = Invoke-WebRequest -Uri "http://$hostName/login?from%2f" -UseBasicParsing -SessionVariable session
$xmlPage = ([xml]$loginPage.Content)
$xmlPage.SelectNodes('//input[@name = "j_password"]').setAttribute('value',$password)
$actionPath = $xmlPage.SelectNodes('//form').action
$responsePage = Invoke-WebRequest -Uri "http://$hostName/$actionPath" -UseBasicParsing -WebSession $session -Body ($xmlPage.SelectNodes('//input').OuterXML) -Method Post