Jenkins-API

 view release on metacpan or  search on metacpan

lib/Jenkins/API.pm  view on Meta::CPAN

you can see on the website in Jenkins can be accessed.  If you have a
job named Test-Project for example with the url C</job/Test-Project> you
can specify the C<< path_parts => ['job', 'Test-Project'] >> to look at the
data for that job alone.

    $jenkins->current_status({
        path_parts => [qw/job Test-Project/],
        extra_params => { depth => 1 },
    });
    # just returns the data relating to job Test-Project.
    # returning it in detail.

The method will die saying 'Invalid response' if the server doesn't
respond as it expects, or die with a JSON decoding error if the JSON
parsing fails.

=head2 get_job_details

Returns detail about the job specified.

    $job_details = $jenkins->get_job_details('Test-Project');
    # {
    #   'actions' => [],
    #   'buildable' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
    #   'builds' => [],
    #   'color' => 'disabled',
    #   'concurrentBuild' => $VAR1->{'buildable'},
    #   'description' => '',
    #   'displayName' => 'Test-Project',
    #   'displayNameOrNull' => undef,
    #   'downstreamProjects' => [],
    #   'firstBuild' => undef,
    #   'healthReport' => [],
    #   'inQueue' => $VAR1->{'buildable'},
    #   'keepDependencies' => $VAR1->{'buildable'},
    #   'lastBuild' => undef,
    #   'lastCompletedBuild' => undef,
    #   'lastFailedBuild' => undef,
    #   'lastStableBuild' => undef,
    #   'lastSuccessfulBuild' => undef,
    #   'lastUnstableBuild' => undef,
    #   'lastUnsuccessfulBuild' => undef,
    #   'name' => 'Test-Project',
    #   'nextBuildNumber' => 1,
    #   'property' => [],
    #   'queueItem' => undef,
    #   'scm' => {},
    #   'upstreamProjects' => [],
    #   'url' => 'http://jenkins-t2:8080/job/Test-Project/'
    # }

The information can be refined in the same way as L</current_status> using C<extra_params>.

=head2 view_status

Provides the status of the specified view.  The list of views is
provided in the general status report.

    $jenkins->view_status('MyView');
    # {
    #   'busyExecutors' => {},
    #   'queueLength' => {},
    #   'totalExecutors' => {},
    #   'totalQueueLength' => {}
    # }
    # {
    #   'description' => undef,
    #   'jobs' => [
    #     {
    #       'color' => 'blue',
    #       'name' => 'Test',
    #       'url' => 'http://jenkins-t2:8080/job/Test/'
    #     }
    #   ],
    #   'name' => 'Test',
    #   'property' => [],
    #   'url' => 'http://jenkins-t2:8080/view/Test/'
    # }

This method allows the same sort of refinement as the L</current_status> method.
To just get the job info from the view for example you can do essentially the same,

    use Data::Dumper;
    my $view_list = $api->current_status({ extra_params => { tree => 'views[name]' }});
    my @views = grep { $_ ne 'All' } map { $_->{name} } @{$view_list->{views}};
    for my $view (@views)
    {
        my $view_jobs = $api->view_status($view, { extra_params => { tree => 'jobs[name,color]' }});
        print Dumper($view_jobs);
    }
    # {
    #   'jobs' => [
    #     {
    #       'color' => 'blue',
    #       'name' => 'Test'
    #     }
    #   ]
    # }

=head2 trigger_build

Trigger a build,

    $success = $jenkins->trigger_build('Test-Project');

If you need to specify a token you can pass that like this,

    $jenkins->trigger_build('Test-Project', { token => $token });

Note that the success response is simply to indicate that the build
has been scheduled, not that the build has succeeded.

=head2 trigger_build_with_parameters

Trigger a build with parameters,

    $success = $jenkins->trigger_build_with_parameters('Test-Project', { Parameter => 'Value' } );

The method behaves the same way as L<trigger_build>.

=head2 build_queue

This returns the items in the build queue.

    $jenkins->build_queue();

This allows the same C<extra_params> as the L</current_status> call.  The
depth and tree parameters work in the same way.  See the Jenkins
API documentation for more details.

The method will die saying 'Invalid response' if the server doesn't
respond as it expects, or die with a JSON decoding error if the JSON
parsing fails.

=head2 load_statistics

This returns the load statistics for the server.

    $jenkins->load_statistics();
    # {
    #   'busyExecutors' => {},
    #   'queueLength' => {},
    #   'totalExecutors' => {},
    #   'totalQueueLength' => {}
    # }

This also allows the same C<extra_params> as the L</current_status> call.  The
depth and tree parameters work in the same way.  See the Jenkins
API documentation for more details.

The method will die saying 'Invalid response' if the server doesn't
respond as it expects, or die with a JSON decoding error if the JSON
parsing fails.

=head2 create_job

Takes the project name and the XML for a config file and gets
Jenkins to create the job.

    my $success = $api->create_job($project_name, $config_xml);

=head2 project_config

This method returns the configuration for the project in XML.

    my $config = $api->project_config($project_name);

=head2 set_project_config

This method allows you to set the configuration for the project using XML.

    my $success = $api->set_project_config($project_name, $config);

=head2 delete_project

Delete the project from Jenkins.

    my $success = $api->delete_project($project_name);

=head2 general_call

This is a catch all method for making a call to the API.  Jenkins is
extensible with plugins which can add new API end points.  We can not
predict all of these so this method allows you to call those functions
without needing a specific method.

general_call($url_parts, $args);

    my $response = $api->general_call(
        ['job', $job, 'api', 'json'],
        {
            method => 'GET',
            extra_params => { tree => 'color,description' },
            decode_json => 1,
            expected_response_code => 200,
        });

    # does a GET /job/$job/api/json?tree=color%2Cdescription
    # decodes the response as json
    # dies if a 200 response isn't returned.



( run in 0.602 second using v1.01-cache-2.11-cpan-39bf76dae61 )