title: Logging into Jenkins via Perl script
body: <p>I am able to change a build's description with the following program. This will change the build's description to "FOO FOO FOO". Unfortunately, my login doesn't work. Right now, this test Jenkins build server has no security on it. However, on our regular Jenkins server, you need to be logged in to change a build's description.:</p>
  
  <pre><code>#! /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            =&gt; "http://build.vegibank.com/",
      USER_ID                 =&gt; "buildguy",
      PASSWORD                =&gt; "swordfish",
  };
  
  use constant {
      LOGIN_URL               =&gt; JENKINS_BASE . '/j_acegi_security_check',
      JOB_URL                 =&gt; JENKINS_BASE . '/job',
      SUBMIT_DESCRIPTION      =&gt; 'submitDescription',
  };
  
  my $job_number = 4;
  my $job_name   = "proginator-2.0";
  my $description = "FOO FOO FOO";
  
  my $user_agent = LWP::UserAgent-&gt;new or die qq(Can't get User Agent);
  
  #
  # My Login Stuff (but it doesn't do anything w/ security off
  #
  
  my $response = $user_agent-&gt;request (
      POST LOGIN_URL,
      [
          j_username =&gt; USER_ID,
          j_password =&gt; PASSWORD,
      ],
  );
  
  $response = $user_agent-&gt;request (
      POST "@{[JOB_URL]}/$job_name/$job_number/@{[SUBMIT_DESCRIPTION]}",
      [
          description =&gt; "$description",
      ],
  );
  </code></pre>
  
  <p>I'm trying to connect to the Jenkins login session, but I don't believe I'm doing it quite right. When I attempt to login, I get a <code>302</code> response and the following dump of my response object:</p>
  
  <pre><code>$VAR1 = bless( {
       '_protocol' =&gt; 'HTTP/1.1',
       '_content' =&gt; '',
       '_rc' =&gt; '302',
       '_headers' =&gt; bless( {
              'connection' =&gt; 'close',
              'client-response-num' =&gt; 1,
              'set-cookie' =&gt; 'JSESSIONID=1D5DF6FAF8714B2ACA4D496FBFE6E983; Path=/jenkins/; HttpOnly',
              'location' =&gt; 'http://build.vegicorp.com/;jsessionid=1D5DF6FAF8714B2ACA4D496FBFE6E983',
              'date' =&gt; 'Mon, 13 May 2013 20:02:35 GMT',
              'client-peer' =&gt; '10.10.21.96:80',
              'content-length' =&gt; '0',
              'client-date' =&gt; 'Mon, 13 May 2013 20:02:35 GMT',
              'content-type' =&gt; 'text/plain; charset=UTF-8',
              'server' =&gt; 'Apache-Coyote/1.1'
      }, 'HTTP::Headers' ),
       '_msg' =&gt; 'Moved Temporarily',
       '_request' =&gt; bless( {
              '_content' =&gt; 'j_username=buildguy&amp;j_password=swordfish',
              '_uri' =&gt; bless( do{\(my $o = 'http://build.vegicorp.com/j_acegi_security_check')}, 'URI::http' ),
              '_headers' =&gt; bless( {
                     'user-agent' =&gt; 'libwww-perl/6.03',
                     'content-type' =&gt; 'application/x-www-form-urlencoded',
                     'content-length' =&gt; 42
       }, 'HTTP::Headers' ),
              '_method' =&gt; 'POST',
              '_uri_canonical' =&gt; $VAR1-&gt;{'_request'}{'_uri'}
       }, 'HTTP::Request' )
  }, 'HTTP::Response' );
  </code></pre>
  
  <p>I figure I must be hitting a valid page since I'm getting a 302 code, but my fields might not be correct (or I'm going to the wrong page).</p>
  
  <p>Can anyone help?</p>