Logging into Jenkins via Perl script -


i able change build's description following program. change build's description "foo foo foo". unfortunately, login doesn't work. right now, test jenkins build server has no security on it. however, on our regular jenkins server, need logged in change build's description.:

#! /usr/bin/env perl  use 5.12.0; use warnings;  use lwp::useragent; use http::request::common qw(post); use data::dumper;  use constant {     jenkins_base            => "http://build.vegibank.com/",     user_id                 => "buildguy",     password                => "swordfish", };  use constant {     login_url               => jenkins_base . '/j_acegi_security_check',     job_url                 => jenkins_base . '/job',     submit_description      => 'submitdescription', };  $job_number = 4; $job_name   = "proginator-2.0"; $description = "foo foo foo";  $user_agent = lwp::useragent->new or die qq(can't user agent);  # # login stuff (but doesn't w/ security off #  $response = $user_agent->request (     post login_url,     [         j_username => user_id,         j_password => password,     ], );  $response = $user_agent->request (     post "@{[job_url]}/$job_name/$job_number/@{[submit_description]}",     [         description => "$description",     ], ); 

i'm trying connect jenkins login session, don't believe i'm doing quite right. when attempt login, 302 response , following dump of response object:

$var1 = bless( {      '_protocol' => 'http/1.1',      '_content' => '',      '_rc' => '302',      '_headers' => bless( {             'connection' => 'close',             'client-response-num' => 1,             'set-cookie' => 'jsessionid=1d5df6faf8714b2aca4d496fbfe6e983; path=/jenkins/; httponly',             'location' => 'http://build.vegicorp.com/;jsessionid=1d5df6faf8714b2aca4d496fbfe6e983',             'date' => 'mon, 13 may 2013 20:02:35 gmt',             'client-peer' => '10.10.21.96:80',             'content-length' => '0',             'client-date' => 'mon, 13 may 2013 20:02:35 gmt',             'content-type' => 'text/plain; charset=utf-8',             'server' => 'apache-coyote/1.1'     }, 'http::headers' ),      '_msg' => 'moved temporarily',      '_request' => bless( {             '_content' => 'j_username=buildguy&j_password=swordfish',             '_uri' => bless( do{\(my $o = 'http://build.vegicorp.com/j_acegi_security_check')}, 'uri::http' ),             '_headers' => bless( {                    'user-agent' => 'libwww-perl/6.03',                    'content-type' => 'application/x-www-form-urlencoded',                    'content-length' => 42      }, 'http::headers' ),             '_method' => 'post',             '_uri_canonical' => $var1->{'_request'}{'_uri'}      }, 'http::request' ) }, 'http::response' ); 

i figure must hitting valid page since i'm getting 302 code, fields might not correct (or i'm going wrong page).

can help?

my authorization failing because ...what technical term? oh yeah... "doing wrong."

after googling , getting lot of unhelpful junk, i, on lark, decided see if jenkins website might have on this. and, did right under page called authenticating scripted clients. in fact, give perl lwp example scripted client.

ha ha, trying hard. seems jenkins use basic http authentication mechanism, , don't have go through conniptions trying figure out how login form works. apparently, jenkins simplifying basic authentication mechanism if authentication mechanism far basic -- program should do.

so, had use basic authentication mechanism.

my $browser = lwp::useragent->new or die qq(cannot user agent); $request = http::request->new; $request->authorization_basic(user_id, password); $request->method("get"); $request->url("$jenkins_url"); $response = $browser->request($request); if ( not $response->is_success ) {     die qq(something went horribly wrong...); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -