gojenkins

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 9 Imported by: 0

README

golang-jenkins
==============

.. image:: https://badges.gitter.im/Join%20Chat.svg
   :alt: Join the chat at https://gitter.im/yosida95/golang-jenkins
   :target: https://gitter.im/yosida95/golang-jenkins?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

-----
About
-----
This is a API client of Jenkins API written in Go.

-----
Usage
-----
``import "github.com/yosida95/golang-jenkins"``

Configure authentication and create an instance of the client:

.. code-block:: go

   auth := &gojenkins.Auth{
      Username: "[jenkins user name]",
      ApiToken: "[jenkins API token]",
   }
   jenkins := gojenkins.NewJenkins(auth, "[jenkins instance base url]")

Make calls against the desired resources:

.. code-block:: go

   job, err := jenkins.GetJob("[job name]")

-------
License
-------
golang-jenkins is licensed under the MIT LICENSE.
See `./LICENSE <./LICENSE>`_.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Causes               []Cause               `json:"causes"`
	Parameter            []Parameter           `json:"parameters"`
	ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
}

type Artifact

type Artifact struct {
	DisplayPath  string `json:"displayPath"`
	FileName     string `json:"fileName"`
	RelativePath string `json:"relativePath"`
}

type Auth

type Auth struct {
	Username string
	ApiToken string
}

type Branches

type Branches struct {
	BranchesSpec []BranchesSpec `xml:"hudson.plugins.git.BranchSpec"`
}

type BranchesSpec

type BranchesSpec struct {
	Name string `xml:"name"`
}

type Build

type Build struct {
	Id     string `json:"id"`
	Number int    `json:"number"`
	Url    string `json:"url"`

	FullDisplayName string `json:"fullDisplayName"`
	Description     string `json:"description"`

	Timestamp         int `json:"timestamp"`
	Duration          int `json:"duration"`
	EstimatedDuration int `json:"estimatedDuration"`

	Building bool   `json:"building"`
	KeepLog  bool   `json:"keepLog"`
	Result   string `json:"result"`

	Artifacts []Artifact `json:"artifacts"`
	Actions   []Action   `json:"actions"`

	ChangeSet ScmChangeSet `json:"changeSet"`
}

type BuildButtonColumn

type BuildButtonColumn struct {
	XMLName xml.Name `xml:"hudson.views.BuildButtonColumn"`
}

type Cause

type Cause struct {
	ShortDescription string `json:"shortDescription"`
	UserId           string `json:"userId"`
	UserName         string `json:"userName"`
	UpstreamCause
}

type ChangeSetItem

type ChangeSetItem struct {
	AffectedPaths []string           `json:"affectedPaths"`
	CommitId      string             `json:"commitId"`
	Timestamp     int                `json:"timestamp"`
	Author        ScmAuthor          `json:"author"`
	Comment       string             `json:"comment"`
	Date          string             `json:"date"`
	Id            string             `json:"id"`
	Message       string             `json:"msg"`
	Paths         []ScmChangeSetPath `json:"paths"`
}

type Column

type Column interface {
}

type Columns

type Columns struct {
	XMLName xml.Name `xml:"columns"`
	Column  []Column
}

type Computer

type Computer struct {
	Actions             []struct{} `json:"actions"`
	Class               string     `json:"_class"`
	DisplayName         string     `json:"displayName"`
	Executors           []struct{} `json:"executors"`
	Idle                bool       `json:"idle"`
	JnlpAgent           bool       `json:"jnlpAgent"`
	LaunchSupported     bool       `json:"launchSupported"`
	ManualLaunchAllowed bool       `json:"manualLaunchAllowed"`
	MonitorData         struct {
		SwapSpaceMonitor struct {
			AvailablePhysicalMemory int64 `json:"availablePhysicalMemory"`
			AvailableSwapSpace      int64 `json:"availableSwapSpace"`
			TotalPhysicalMemory     int64 `json:"totalPhysicalMemory"`
			TotalSwapSpace          int64 `json:"totalSwapSpace"`
		} `json:"hudson.node_monitors.SwapSpaceMonitor"`
		TemporarySpaceMonitor struct {
			Timestamp int64  `json:"timestamp"`
			Path      string `json:"path"`
			Size      int64  `json:"size"`
		} `json:"hudson.node_monitors.TemporarySpaceMonitor"`
		DiskSpaceMonitor struct {
			Timestamp int64  `json:"timestamp"`
			Path      string `json:"path"`
			Size      int64  `json:"size"`
		} `json:"hudson.node_monitors.DiskSpaceMonitor"`
		ArchitectureMonitor string `json:"hudson.node_monitors.ArchitectureMonitor"`
		ResponseTimeMonitor struct {
			Timestamp int64 `json:"timestamp"`
			Average   int64 `json:"average"`
		} `json:"hudson.node_monitors.ResponseTimeMonitor"`
		ClockMonitor struct {
			Diff int64 `json:"diff"`
		} `json:"hudson.node_monitors.ClockMonitor"`
	} `json:"monitorData"`
	NumExecutors       int    `json:"numExecutors"`
	Offline            bool   `json:"offline"`
	OfflineCauseReason string `json:"offlineCauseReason"`
	TemporarilyOffline bool   `json:"temporarilyOffline"`
}

type ComputerObject

type ComputerObject struct {
	BusyExecutors  int        `json:"busyExecutors"`
	Computers      []Computer `json:"computer"`
	DisplayName    string     `json:"displayName"`
	TotalExecutors int        `json:"totalExecutors"`
}

type GitBrowser

type GitBrowser struct {
	Class       string `xml:"class,attr"`
	Url         string `xml:"url"`
	ProjectName string `xml:"projectName"`
}

type GitExtensions

type GitExtensions struct {
	Class       string      `xml:"class,attr"`
	LocalBranch LocalBranch `xml:"hudson.plugins.git.extensions.impl.LocalBranch"`
}

type GitSubmoduleCfg

type GitSubmoduleCfg struct {
	Class string `xml:"class,attr"`
}

type Health

type Health struct {
	Description string `json:"description"`
}

type Item

type Item struct {
	Actions                    []Action `json:"actions"`
	Blocked                    bool     `json:"blocked"`
	Buildable                  bool     `json:"buildable"`
	Id                         int      `json:"id"`
	InQueueSince               int64    `json:"inQueueSince"`
	Params                     string   `json:"params"`
	Stuck                      bool     `json:"stuck"`
	Task                       Task     `json:"task"`
	URL                        string   `json:"url"`
	Why                        string   `json:"why"`
	BuildableStartMilliseconds int64    `json:"buildableStartMilliseconds"`
	Pending                    bool     `json:"pending"`
}

type Jenkins

type Jenkins struct {
	// contains filtered or unexported fields
}

func NewJenkins

func NewJenkins(auth *Auth, baseUrl string) *Jenkins

func (*Jenkins) AddJobToView

func (jenkins *Jenkins) AddJobToView(viewName string, job Job) error

Add job to view

func (*Jenkins) Build

func (jenkins *Jenkins) Build(job Job, params url.Values) error

Create a new build for this job. Params can be nil.

func (*Jenkins) CreateJob

func (jenkins *Jenkins) CreateJob(mavenJobItem MavenJobItem, jobName string) error

Create a new job

func (*Jenkins) CreateView

func (jenkins *Jenkins) CreateView(listView ListView) error

Create a new view

func (*Jenkins) DeleteJob

func (jenkins *Jenkins) DeleteJob(job Job) error

Delete a job

func (*Jenkins) GetArtifact

func (jenkins *Jenkins) GetArtifact(build Build, artifact Artifact) ([]byte, error)

GetArtifact return the content of a build artifact

func (*Jenkins) GetBuild

func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error)

GetBuild returns a number-th build result of specified job.

func (*Jenkins) GetBuildConsoleOutput

func (jenkins *Jenkins) GetBuildConsoleOutput(build Build) ([]byte, error)

Get the console output from a build.

func (*Jenkins) GetComputer

func (jenkins *Jenkins) GetComputer(name string) (computer Computer, err error)

GetComputer returns a Computer object with a specified name.

func (*Jenkins) GetComputerObject

func (jenkins *Jenkins) GetComputerObject() (co ComputerObject, err error)

GetComputerObject returns the main ComputerObject

func (*Jenkins) GetComputers

func (jenkins *Jenkins) GetComputers() ([]Computer, error)

GetComputers returns the list of all Computer objects

func (*Jenkins) GetJob

func (jenkins *Jenkins) GetJob(name string) (job Job, err error)

GetJob returns a job which has specified name.

func (*Jenkins) GetJobConfig

func (jenkins *Jenkins) GetJobConfig(name string) (job MavenJobItem, err error)

GetJobConfig returns a maven job, has the one used to create Maven job

func (*Jenkins) GetJobs

func (jenkins *Jenkins) GetJobs() ([]Job, error)

GetJobs returns all jobs you can read.

func (*Jenkins) GetJobsByViews added in v1.0.1

func (jenkins *Jenkins) GetJobsByViews(views []string) ([]Job, error)

GetJobsByViews returns jobs of views you can read.

func (*Jenkins) GetLastBuild

func (jenkins *Jenkins) GetLastBuild(job Job) (build Build, err error)

GetLastBuild returns the last build of specified job.

func (*Jenkins) GetQueue

func (jenkins *Jenkins) GetQueue() (queue Queue, err error)

GetQueue returns the current build queue from Jenkins

func (*Jenkins) SetBuildDescription

func (jenkins *Jenkins) SetBuildDescription(build Build, description string) error

SetBuildDescription sets the description of a build

func (*Jenkins) SetHTTPClient

func (jenkins *Jenkins) SetHTTPClient(client *http.Client)

SetHTTPClient with timeouts or insecure transport, etc.

type Job

type Job struct {
	Actions []Action `json:"actions"`
	Name    string   `json:"name"`
	Url     string   `json:"url"`
	Color   string   `json:"color"`

	Buildable    bool     `json:"buildable"`
	Builds       []Build  `json:"builds"`
	DisplayName  string   `json:"displayName"`
	Description  string   `json:"description"`
	HealthReport []Health `json:"healthReport"`

	LastCompletedBuild    Build `json:"lastCompletedBuild"`
	LastFailedBuild       Build `json:"lastFailedBuild"`
	LastStableBuild       Build `json:"lastStableBuild"`
	LastSuccessfulBuild   Build `json:"lastSuccessfulBuild"`
	LastUnstableBuild     Build `json:"lastUnstableBuild"`
	LastUnsuccessfulBuild Build `json:"lastUnsuccessfulBuild"`

	Property []Property `json:"property"`
}

type JobColumn

type JobColumn struct {
	XMLName xml.Name `xml:"hudson.views.JobColumn"`
}

type JobParameter

type JobParameter struct {
	Default     Parameter `json:"defaultParameterValue"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Type        string    `json:"type"`
	Choices     []string  `json:"choices"`
}

type JobProperties

type JobProperties struct {
}

type JobSetting

type JobSetting struct {
}

type JobSettings

type JobSettings struct {
	Class      string `xml:"class,attr"`
	JobSetting []JobSetting
}

type LastDurationColumn

type LastDurationColumn struct {
	XMLName xml.Name `xml:"hudson.views.LastDurationColumn"`
}

type LastFailureColumn

type LastFailureColumn struct {
	XMLName xml.Name `xml:"hudson.views.LastFailureColumn"`
}

type LastSuccessColumn

type LastSuccessColumn struct {
	XMLName xml.Name `xml:"hudson.views.LastSuccessColumn"`
}

type ListView

type ListView struct {
	XMLName         xml.Name `xml:"hudson.model.ListView"`
	Name            string   `xml:"name"`
	FilterExecutors bool     `xml:"filterExecutors"`
	FilterQueue     bool     `xml:"filterQueue"`
	Columns         Columns  `xml:"columns"`
}

func NewListView

func NewListView(name string) ListView

type LocalBranch

type LocalBranch struct {
	LocalBranch string `xml:"localBranch"`
}

type Locations

type Locations struct {
	Location []ScmSvnLocation `xml:"hudson.scm.SubversionSCM_-ModuleLocation"`
}

type MavenJobItem

type MavenJobItem struct {
	XMLName                          struct{}             `xml:"maven2-moduleset"`
	Plugin                           string               `xml:"plugin,attr"`
	Actions                          string               `xml:"actions"`
	Description                      string               `xml:"description"`
	KeepDependencies                 string               `xml:"keepDependencies"`
	Properties                       JobProperties        `xml:"properties"`
	Scm                              Scm                  `xml:"scm"`
	CanRoam                          string               `xml:"canRoam"`
	Disabled                         string               `xml:"disabled"`
	BlockBuildWhenDownstreamBuilding string               `xml:"blockBuildWhenDownstreamBuilding"`
	BlockBuildWhenUpstreamBuilding   string               `xml:"blockBuildWhenUpstreamBuilding"`
	Triggers                         Triggers             `xml:"triggers"`
	ConcurrentBuild                  string               `xml:"concurrentBuild"`
	Goals                            string               `xml:"goals"`
	AggregatorStyleBuild             string               `xml:"aggregatorStyleBuild"`
	IncrementalBuild                 string               `xml:"incrementalBuild"`
	IgnoreUpstremChanges             string               `xml:"ignoreUpstremChanges"`
	ArchivingDisabled                string               `xml:"archivingDisabled"`
	SiteArchivingDisabled            string               `xml:"siteArchivingDisabled"`
	FingerprintingDisabled           string               `xml:"fingerprintingDisabled"`
	ResolveDependencies              string               `xml:"resolveDependencies"`
	ProcessPlugins                   string               `xml:"processPlugins"`
	MavenName                        string               `xml:"mavenName"`
	MavenValidationLevel             string               `xml:"mavenValidationLevel"`
	DefaultGoals                     string               `xml:"defaultGoals"`
	RunHeadless                      string               `xml:"runHeadless"`
	DisableTriggerDownstreamProjects string               `xml:"disableTriggerDownstreamProjects"`
	Settings                         JobSettings          `xml:"settings"`
	GlobalSettings                   JobSettings          `xml:"globalSettings"`
	RunPostStepsIfResult             RunPostStepsIfResult `xml:"runPostStepsIfResult"`
	Postbuilders                     PostBuilders         `xml:"postbuilders"`
}

type Parameter

type Parameter struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

Parameter for a build

type ParameterDefinition

type ParameterDefinition struct {
	Name string `json:"name"`
}

type PostBuilder

type PostBuilder interface {
}

type PostBuilders

type PostBuilders struct {
	XMLName     xml.Name `xml:"postbuilders"`
	PostBuilder []PostBuilder
}

type Property

type Property struct {
	Parameters []JobParameter `json:"parameterDefinitions"`
}

type Queue

type Queue struct {
	Items []Item `json:"items"`
}

type RunPostStepsIfResult

type RunPostStepsIfResult struct {
	Name          string `xml:"name"`
	Ordinal       string `xml:"ordinal"`
	Color         string `xml:"color"`
	CompleteBuild string `xml:"completeBuild"`
}

type Scm

type Scm struct {
	ScmContent
	Class  string `xml:"class,attr"`
	Plugin string `xml:"plugin,attr"`
}

func (*Scm) UnmarshalXML

func (iscm *Scm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.UnmarshalXML intrface Decode between multiple types of Scm. for now only SVN is supported

type ScmAuthor

type ScmAuthor struct {
	FullName    string `json:"fullName"`
	AbsoluteUrl string `json:"absoluteUrl"`
}

type ScmChangeSet

type ScmChangeSet struct {
	Kind  string          `json:"kind"`
	Items []ChangeSetItem `json:"items"`
}

type ScmChangeSetPath

type ScmChangeSetPath struct {
	EditType string `json:"editType"`
	File     string `json:"File"`
}

type ScmContent

type ScmContent interface{}

type ScmGit

type ScmGit struct {
	UserRemoteConfigs                 UserRemoteConfigs `xml:"userRemoteConfigs"`
	Branches                          Branches          `xml:"branches"`
	DoGenerateSubmoduleConfigurations bool              `xml:"doGenerateSubmoduleConfigurations"`
	GitBrowser                        GitBrowser        `xml:"browser"`
	GitSubmoduleCfg                   GitSubmoduleCfg   `xml:"submoduleCfg"`
	GitExtensions                     GitExtensions     `xml:"extensions"`
}

type ScmSvn

type ScmSvn struct {
	Locations              Locations        `xml:"locations"`
	ExcludedRegions        string           `xml:"excludedRegions"`
	IncludedRegions        string           `xml:"includedRegions"`
	ExcludedUsers          string           `xml:"excludedUsers"`
	ExcludedRevprop        string           `xml:"excludedRevprop"`
	ExcludedCommitMessages string           `xml:"excludedCommitMessages"`
	WorkspaceUpdater       WorkspaceUpdater `xml:"workspaceUpdater"`
	IgnoreDirPropChanges   string           `xml:"ignoreDirPropChanges"`
	FilterChangelog        string           `xml:"filterChangelog"`
}

type ScmSvnLocation

type ScmSvnLocation struct {
	Remote                string `xml:"remote"`
	Local                 string `xml:"local"`
	DepthOption           string `xml:"depthOption"`
	IgnoreExternalsOption string `xml:"ignoreExternalsOption"`
}

type ScmTrigger

type ScmTrigger struct {
	XMLName               struct{} `xml:"hudson.triggers.SCMTrigger"`
	Spec                  string   `xml:"spec"`
	IgnorePostCommitHooks string   `xml:"ignorePostCommitHooks"`
}

type ShellBuilder

type ShellBuilder struct {
	XMLName xml.Name `xml:"hudson.tasks.Shell"`
	Command string   `xml:"command"`
}

type StatusColumn

type StatusColumn struct {
	XMLName xml.Name `xml:"hudson.views.StatusColumn"`
}

type Task

type Task struct {
	Name  string `json:"name"`
	Url   string `json:"url"`
	Color string `json:"color"`
}

type Trigger

type Trigger interface {
}

type Triggers

type Triggers struct {
	Trigger []Trigger
}

type UpstreamCause

type UpstreamCause struct {
	ShortDescription string `json:"shortDescription"`
	UpstreamBuild    int    `json:"upstreamBuild"`
	UpstreamProject  string `json:"upstreamProject"`
	UpstreamUrl      string `json:"upstreamUrl"`
}

type UserRemoteConfig

type UserRemoteConfig struct {
	Urls []string `xml:"url"`
}

type UserRemoteConfigs

type UserRemoteConfigs struct {
	UserRemoteConfig UserRemoteConfig `xml:"hudson.plugins.git.UserRemoteConfig"`
}

type WeatherColumn

type WeatherColumn struct {
	XMLName xml.Name `xml:"hudson.views.WeatherColumn"`
}

type WorkspaceUpdater

type WorkspaceUpdater struct {
	Class string `xml:"class,attr"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL