Skip to content

a light weight, object-oriented .Net SDK for interacting with Jenkins

License

Notifications You must be signed in to change notification settings

mattumotu/jenkinsnetclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JenkinsNet

JenkinsNET Logo

Allows for easy and simple C# interaction with Jenkins.

Build status Coverage Status Quality Gate NuGet

Installation

Via NuGet

PM> Install-Package JenkinsNetClient

Usage

Basics

First you need a connection to a jenkins server, just pass it your jenkins instance's url.

JenkinsConnection myConn = new JenkinsConnection("myjenkins");

If Jenkins is secuired then you will have to provide a username and api token:

JenkinsConnection myConn = new JenkinsConnection("myjenkins", "username", "apitoken");

We can get a list of Views and Jobs from a JenkinsServer

var myJenkins = new JenkinsServer(myConn);
List<JenkinsView> views = myJenkins.Views();
List<JenkinsJob> jobs = myJenkins.Jobs();

Playing with views

We can easily create a new view ...

var newView = new JenkinsView(myConn, "hudson.model.ListView", "Name of my new view");
if(newView.Exists()) 
{
  throw new exception("View already exists on jenkins");
}
newView.Create(); // Create on jenkins
if(!newView.Exists()) 
{
  throw new exception("View doesn't exist on jenkins - Create must have failed");
}

... or delete an existing view

JenkinsView existingView = views[0];
existingView.Delete(); // Delete from jenkins
if(existingView.Exists()) 
{
  throw new exception("View still exists on jenkins - delete failed");
}

Playing with Jobs

var newJob = new JenkinsJob(myConn, "hudson.model.FreeStyleProject", "name of new job");
if(newJob.Exists()) 
{
  throw new exception("job already exists on jenkins");
}
newJob.Create(); // Create job on jenkins
if(!newJob.Exists()) 
{
  throw new exception("job doesn't exist on jenkins after call to create");
}
newJob.Delete();
if(newJob.Exists()) 
{
  throw new exception("job still exists on jenkins after call to delete");
}           

Jobs and Views

Adding an existing job to a view ...

JenkinsJob existingJob = Jobs[0];
JenkinsView existingView = views[0];
if(!existingView.Contains(existingJob))
{
  existingView.Add(existingJob);
}
if(!existingView.Contains(existingJob)) 
{
  throw new exception("Add failed");
}

... and removing it again.

existingView.Remove(existingJob);
if(existingView.Contains(existingJob)) 
{
  throw new exception("job still on view - remove failed");
}

Getting and Setting config.xml

Getting the config xml for a job

JenkinsJob existingJob = Jobs[0];
string configXml = existingJob.Config;

and setting it

JenkinsJob existingJob = Jobs[0];
existingJob.Config = xml

About

a light weight, object-oriented .Net SDK for interacting with Jenkins

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages