gojenkins

package module
v0.0.0-...-5b1d6fc Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

Jenkins API Client for Go

GoDoc Go Report Cart Build Status

About

Jenkins is the most popular Open Source Continuous Integration system. This Library will help you interact with Jenkins in a more developer-friendly way.

These are some of the features that are currently implemented:

  • Get information on test-results of completed/failed build
  • Ability to query Nodes, and manipulate them. Start, Stop, set Offline.
  • Ability to query Jobs, and manipulate them.
  • Get Plugins, Builds, Artifacts, Fingerprints
  • Validate Fingerprints of Artifacts
  • Create and Delete Users
  • Get Current Queue, Cancel Tasks
  • Create and Revoke API Tokens
  • etc. For all methods go to GoDoc Reference.

Installation

go get github.com/bndr/gojenkins

CLI

For users that would like CLI based on gojenkins, follow the steps below:

$ cd cli/jenkinsctl
$ make

Usage


import (
  "github.com/bndr/gojenkins"
  "context"
  "time"
  "fmt"
)

ctx := context.Background()
jenkins := gojenkins.CreateJenkins(nil, "http://localhost:8080/", "admin", "admin")
// Provide CA certificate if server is using self-signed certificate
// caCert, _ := ioutil.ReadFile("/tmp/ca.crt")
// jenkins.Requester.CACert = caCert
_, err := jenkins.Init(ctx)


if err != nil {
  panic("Something Went Wrong")
}

job, err := jenkins.GetJob(ctx, "#jobname")
if err != nil {
  panic(err)
}
queueid, err := job.InvokeSimple(ctx, params) // or  jenkins.BuildJob(ctx, "#jobname", params)
if err != nil {
  panic(err)
}
build, err := jenkins.GetBuildFromQueueID(ctx, job, queueid)
if err != nil {
  panic(err)
}

// Wait for build to finish
for build.IsRunning(ctx) {
  time.Sleep(5000 * time.Millisecond)
  build.Poll(ctx)
}

fmt.Printf("build number %d with result: %v\n", build.GetBuildNumber(), build.GetResult())

API Reference: https://godoc.org/github.com/bndr/gojenkins

Examples

For all of the examples below first create a jenkins object

import "github.com/bndr/gojenkins"

jenkins, _ := gojenkins.CreateJenkins(nil, "http://localhost:8080/", "admin", "admin").Init(ctx)

or if you don't need authentication:

jenkins, _ := gojenkins.CreateJenkins(nil, "http://localhost:8080/").Init(ctx)

you can also specify your own http.Client (for instance, providing your own SSL configurations):

client := &http.Client{ ... }
jenkins, := gojenkins.CreateJenkins(client, "http://localhost:8080/").Init(ctx)

By default, gojenkins will use the http.DefaultClient if none is passed into the CreateJenkins() function.

Check Status of all nodes
nodes := jenkins.GetAllNodes(ctx)

for _, node := range nodes {

  // Fetch Node Data
  node.Poll(ctx)
	if node.IsOnline(ctx) {
		fmt.Println("Node is Online")
	}
}

Get all Builds for specific Job, and check their status
jobName := "someJob"
builds, err := jenkins.GetAllBuildIds(ctx, jobName)

if err != nil {
  panic(err)
}

for _, build := range builds {
  buildId := build.Number
  data, err := jenkins.GetBuild(ctx, jobName, buildId)

  if err != nil {
    panic(err)
  }

	if "SUCCESS" == data.GetResult(ctx) {
		fmt.Println("This build succeeded")
	}
}

// Get Last Successful/Failed/Stable Build for a Job
job, err := jenkins.GetJob(ctx, "someJob")

if err != nil {
  panic(err)
}

job.GetLastSuccessfulBuild(ctx)
job.GetLastStableBuild(ctx)

Get Current Tasks in Queue, and the reason why they're in the queue

tasks := jenkins.GetQueue(ctx)

for _, task := range tasks {
	fmt.Println(task.GetWhy(ctx))
}

Create View and add Jobs to it

view, err := jenkins.CreateView(ctx, "test_view", gojenkins.LIST_VIEW)

if err != nil {
  panic(err)
}

status, err := view.AddJob(ctx, "jobName")

if status != nil {
  fmt.Println("Job has been added to view")
}

Create nested Folders and create Jobs in them

// Create parent folder
pFolder, err := jenkins.CreateFolder(ctx, "parentFolder")
if err != nil {
  panic(err)
}

// Create child folder in parent folder
cFolder, err := jenkins.CreateFolder(ctx, "childFolder", pFolder.GetName())
if err != nil {
  panic(err)
}

// Create job in child folder
configString := `<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers class="vector"/>
  <concurrentBuild>false</concurrentBuild>
  <builders/>
  <publishers/>
  <buildWrappers/>
</project>`

job, err := jenkins.CreateJobInFolder(ctx, configString, "jobInFolder", pFolder.GetName(), cFolder.GetName())
if err != nil {
  panic(err)
}

if job != nil {
	fmt.Println("Job has been created in child folder")
}

Get All Artifacts for a Build and Save them to a folder

job, _ := jenkins.GetJob(ctx, "job")
build, _ := job.GetBuild(ctx, 1)
artifacts := build.GetArtifacts(ctx)

for _, a := range artifacts {
	a.SaveToDir("/tmp")
}

To always get fresh data use the .Poll() method

job, _ := jenkins.GetJob(ctx, "job")
job.Poll()

build, _ := job.getBuild(ctx, 1)
build.Poll()

Create and Delete Users
// Create user
user, err := jenkins.CreateUser(ctx, "username", "password", "fullname", "user@email.com")
if err != nil {
  log.Fatal(err)
}
// Delete User
err = user.Delete()
if err != nil {
  log.Fatal(err)
}
// Delete user not created by gojenkins
err = jenkins.DeleteUser("username")

Create and Revoke API Tokens

// Create a token for admin user
token, err := jenkins.GenerateAPIToken(ctx, "TestToken")
if err != nil {
  log.Fatal(err)
}

// Set Jenkins client to use new API token
jenkins.Requester.BasicAuth.Password = token.Value

// Revoke token that was just created
token.Revoke()

// Revoke all tokens for admin user
err = jenkins.RevokeAllAPITokens(ctx)
if err != nil {
  log.Fatal(err)
}

Testing

go test

Contribute

All Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.

TODO

Although the basic features are implemented there are many optional features that are on the todo list.

  • Kerberos Authentication
  • Rewrite some (all?) iterators with channels

LICENSE

Apache License 2.0

Documentation

Overview

Gojenkins is a Jenkins Client in Go, that exposes the jenkins REST api in a more developer friendly way.

Index

Constants

View Source
const (
	STATUS_FAIL           = "FAIL"
	STATUS_ERROR          = "ERROR"
	STATUS_ABORTED        = "ABORTED"
	STATUS_REGRESSION     = "REGRESSION"
	STATUS_SUCCESS        = "SUCCESS"
	STATUS_FIXED          = "FIXED"
	STATUS_PASSED         = "PASSED"
	RESULT_STATUS_FAILURE = "FAILURE"
	RESULT_STATUS_FAILED  = "FAILED"
	RESULT_STATUS_SKIPPED = "SKIPPED"
	STR_RE_SPLIT_VIEW     = "(.*)/view/([^/]*)/?"
)
View Source
const ClassUsernameCredentials = "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"

ClassUsernameCredentials is name if java class which implements credentials that store username-password pair

View Source
const KeySourceDirectEntryType = "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource"

KeySourceDirectEntryType is used when secret in provided directly as private key value

View Source
const KeySourceOnMasterType = "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$FileOnMasterPrivateKeySource"

KeySourceOnMasterType is used when private key value is path to file on jenkins master

Variables

View Source
var (
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)

Loggers

View Source
var (
	LIST_VIEW      = "hudson.model.ListView"
	NESTED_VIEW    = "hudson.plugins.nested_view.NestedView"
	MY_VIEW        = "hudson.model.MyView"
	DASHBOARD_VIEW = "hudson.plugins.view.dashboard.Dashboard"
	PIPELINE_VIEW  = "au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView"
)

Functions

This section is empty.

Types

type APIRequest

type APIRequest struct {
	Method   string
	Endpoint string
	Payload  io.Reader
	Headers  http.Header
	Suffix   string
}

func NewAPIRequest

func NewAPIRequest(method string, endpoint string, payload io.Reader) *APIRequest

func (*APIRequest) SetHeader

func (ar *APIRequest) SetHeader(key string, value string) *APIRequest

type APIToken

type APIToken struct {
	Jenkins *Jenkins
	Name    string `json:"tokenName"`
	UUID    string `json:"tokenUuid"`
	Value   string `json:"tokenValue"`
}

APIToken is a Jenkins API token to be created for the user instantiated with the Jenkins client

func (*APIToken) Revoke

func (a *APIToken) Revoke() error

Revoke revokes an API token

type APITokenGenerateResponse

type APITokenGenerateResponse struct {
	Status string   `json:"status"`
	Data   APIToken `json:"data"`
}

APITokenGenerateResponse is the response given by Jenkins when an API token is created

type Artifact

type Artifact struct {
	Jenkins  *Jenkins
	Build    *Build
	FileName string
	Path     string
}

Represents an Artifact

func (Artifact) GetData

func (a Artifact) GetData(ctx context.Context) ([]byte, error)

Get raw byte data of Artifact

func (Artifact) Save

func (a Artifact) Save(ctx context.Context, path string) (bool, error)

Save artifact to a specific path, using your own filename.

func (Artifact) SaveToDir

func (a Artifact) SaveToDir(ctx context.Context, dir string) (bool, error)

Save Artifact to directory using Artifact filename.

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

Basic Authentication

type Build

type Build struct {
	Raw     *BuildResponse
	Job     *Job
	Jenkins *Jenkins
	Base    string
	Depth   int
}

func (*Build) GetActions

func (b *Build) GetActions() []generalObj

func (*Build) GetAllFingerPrints

func (b *Build) GetAllFingerPrints(ctx context.Context) []*FingerPrint

func (*Build) GetArtifacts

func (b *Build) GetArtifacts() []Artifact

func (*Build) GetBuildNumber

func (b *Build) GetBuildNumber() int64

func (*Build) GetCauses

func (b *Build) GetCauses(ctx context.Context) ([]map[string]interface{}, error)

func (*Build) GetConsoleOutput

func (b *Build) GetConsoleOutput(ctx context.Context) string

func (*Build) GetConsoleOutputFromIndex

func (b *Build) GetConsoleOutputFromIndex(ctx context.Context, startID int64) (consoleResponse, error)

func (*Build) GetCulprits

func (b *Build) GetCulprits() []Culprit

func (*Build) GetDownstreamBuilds

func (b *Build) GetDownstreamBuilds(ctx context.Context) ([]*Build, error)

func (*Build) GetDownstreamJobNames

func (b *Build) GetDownstreamJobNames(ctx context.Context) []string

func (*Build) GetDuration

func (b *Build) GetDuration() float64

func (*Build) GetInjectedEnvVars

func (b *Build) GetInjectedEnvVars(ctx context.Context) (map[string]string, error)

func (*Build) GetMatrixRuns

func (b *Build) GetMatrixRuns(ctx context.Context) ([]*Build, error)

func (*Build) GetParameters

func (b *Build) GetParameters() []parameter

func (*Build) GetResult

func (b *Build) GetResult() string

func (*Build) GetResultSet

func (b *Build) GetResultSet(ctx context.Context) (*TestResult, error)

func (*Build) GetRevision

func (b *Build) GetRevision() string

func (*Build) GetRevisionBranch

func (b *Build) GetRevisionBranch() string

func (*Build) GetTimestamp

func (b *Build) GetTimestamp() time.Time

func (*Build) GetUpstreamBuild

func (b *Build) GetUpstreamBuild(ctx context.Context) (*Build, error)

func (*Build) GetUpstreamBuildNumber

func (b *Build) GetUpstreamBuildNumber(ctx context.Context) (int64, error)

func (*Build) GetUpstreamJob

func (b *Build) GetUpstreamJob(ctx context.Context) (*Job, error)

func (*Build) GetUrl

func (b *Build) GetUrl() string

func (*Build) Info

func (b *Build) Info() *BuildResponse

Builds

func (*Build) IsGood

func (b *Build) IsGood(ctx context.Context) bool

func (*Build) IsRunning

func (b *Build) IsRunning(ctx context.Context) bool

func (*Build) Poll

func (b *Build) Poll(ctx context.Context, options ...interface{}) (int, error)

Poll for current data. Optional parameter - depth. More about depth here: https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

func (*Build) SetDescription

func (b *Build) SetDescription(ctx context.Context, description string) error

func (*Build) Stop

func (b *Build) Stop(ctx context.Context) (bool, error)

type BuildResponse

type BuildResponse struct {
	Actions   []generalObj
	Artifacts []struct {
		DisplayPath  string `json:"displayPath"`
		FileName     string `json:"fileName"`
		RelativePath string `json:"relativePath"`
	} `json:"artifacts"`
	Building  bool   `json:"building"`
	BuiltOn   string `json:"builtOn"`
	ChangeSet struct {
		Items []struct {
			AffectedPaths []string `json:"affectedPaths"`
			Author        struct {
				AbsoluteUrl string `json:"absoluteUrl"`
				FullName    string `json:"fullName"`
			} `json:"author"`
			Comment  string `json:"comment"`
			CommitID string `json:"commitId"`
			Date     string `json:"date"`
			ID       string `json:"id"`
			Msg      string `json:"msg"`
			Paths    []struct {
				EditType string `json:"editType"`
				File     string `json:"file"`
			} `json:"paths"`
			Timestamp int64 `json:"timestamp"`
		} `json:"items"`
		Kind      string `json:"kind"`
		Revisions []struct {
			Module   string
			Revision int
		} `json:"revision"`
	} `json:"changeSet"`
	ChangeSets []struct {
		Items []struct {
			AffectedPaths []string `json:"affectedPaths"`
			Author        struct {
				AbsoluteUrl string `json:"absoluteUrl"`
				FullName    string `json:"fullName"`
			} `json:"author"`
			Comment  string `json:"comment"`
			CommitID string `json:"commitId"`
			Date     string `json:"date"`
			ID       string `json:"id"`
			Msg      string `json:"msg"`
			Paths    []struct {
				EditType string `json:"editType"`
				File     string `json:"file"`
			} `json:"paths"`
			Timestamp int64 `json:"timestamp"`
		} `json:"items"`
		Kind      string `json:"kind"`
		Revisions []struct {
			Module   string
			Revision int
		} `json:"revision"`
	} `json:"changeSets"`
	Culprits          []Culprit   `json:"culprits"`
	Description       interface{} `json:"description"`
	Duration          float64     `json:"duration"`
	EstimatedDuration float64     `json:"estimatedDuration"`
	Executor          interface{} `json:"executor"`
	DisplayName       string      `json:"displayName"`
	FullDisplayName   string      `json:"fullDisplayName"`
	ID                string      `json:"id"`
	KeepLog           bool        `json:"keepLog"`
	Number            int64       `json:"number"`
	QueueID           int64       `json:"queueId"`
	Result            string      `json:"result"`
	Timestamp         int64       `json:"timestamp"`
	URL               string      `json:"url"`
	MavenArtifacts    interface{} `json:"mavenArtifacts"`
	MavenVersionUsed  string      `json:"mavenVersionUsed"`
	FingerPrint       []FingerPrintResponse
	Runs              []struct {
		Number int64
		URL    string
	} `json:"runs"`
}

type BuildRevision

type BuildRevision struct {
	SHA1   string   `json:"SHA1"`
	Branch []branch `json:"branch"`
}

type Builds

type Builds struct {
	BuildNumber int64         `json:"buildNumber"`
	BuildResult interface{}   `json:"buildResult"`
	Marked      BuildRevision `json:"marked"`
	Revision    BuildRevision `json:"revision"`
}

type Computers

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

type CredentialsManager

type CredentialsManager struct {
	J      *Jenkins
	Folder string
}

CredentialsManager is utility to control credential plugin Credentials declared by it can be used in jenkins jobs

func (CredentialsManager) Add

func (cm CredentialsManager) Add(ctx context.Context, domain string, creds interface{}) error

Add credential to given domain, creds must be struct which is parsable to xml

func (CredentialsManager) Delete

func (cm CredentialsManager) Delete(ctx context.Context, domain string, id string) error

Delete credential in given domain with given id

func (CredentialsManager) GetSingle

func (cm CredentialsManager) GetSingle(ctx context.Context, domain string, id string, creds interface{}) error

GetSingle searches for credential in given domain with given id, if credential is found it will be parsed as xml to creds parameter(creds must be pointer to struct)

func (CredentialsManager) List

func (cm CredentialsManager) List(ctx context.Context, domain string) ([]string, error)

List ids if credentials stored inside provided domain

func (CredentialsManager) Update

func (cm CredentialsManager) Update(ctx context.Context, domain string, id string, creds interface{}) error

Update credential in given domain with given id, creds must be pointer to struct which is parsable to xml

type Culprit

type Culprit struct {
	AbsoluteUrl string
	FullName    string
}

type DockerServerCredentials

type DockerServerCredentials struct {
	XMLName             xml.Name `xml:"org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials"`
	ID                  string   `xml:"id"`
	Scope               string   `xml:"scope"`
	Username            string   `xml:"username"`
	Description         string   `xml:"description,omitempty"`
	ClientKey           string   `xml:"clientKey"`
	ClientCertificate   string   `xml:"clientCertificate"`
	ServerCaCertificate string   `xml:"serverCaCertificate"`
}

DockerServerCredentials store credentials for docker keys.

type ErrAPIToken

type ErrAPIToken struct {
	Message string
}

ErrAPIToken occurs when there is error creating or revoking API tokens

func (*ErrAPIToken) Error

func (e *ErrAPIToken) Error() string

type ErrUser

type ErrUser struct {
	Message string
}

ErrUser occurs when there is error creating or revoking Jenkins users

func (*ErrUser) Error

func (e *ErrUser) Error() string

type Executor

type Executor struct {
	Raw     *ExecutorResponse
	Jenkins *Jenkins
}

type ExecutorResponse

type ExecutorResponse struct {
	AssignedLabels  []map[string]string `json:"assignedLabels"`
	Description     interface{}         `json:"description"`
	Jobs            []InnerJob          `json:"jobs"`
	Mode            string              `json:"mode"`
	NodeDescription string              `json:"nodeDescription"`
	NodeName        string              `json:"nodeName"`
	NumExecutors    int64               `json:"numExecutors"`
	OverallLoad     struct{}            `json:"overallLoad"`
	PrimaryView     struct {
		Name string `json:"name"`
		URL  string `json:"url"`
	} `json:"primaryView"`
	QuietingDown   bool       `json:"quietingDown"`
	SlaveAgentPort int64      `json:"slaveAgentPort"`
	UnlabeledLoad  struct{}   `json:"unlabeledLoad"`
	UseCrumbs      bool       `json:"useCrumbs"`
	UseSecurity    bool       `json:"useSecurity"`
	Views          []ViewData `json:"views"`
}

type FileCredentials

type FileCredentials struct {
	XMLName     xml.Name `xml:"org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl"`
	ID          string   `xml:"id"`
	Scope       string   `xml:"scope"`
	Description string   `xml:"description"`
	Filename    string   `xml:"fileName"`
	SecretBytes string   `xml:"secretBytes"`
}

FileCredentials store a file "SecretBytes" is a base64 encoded file content

type FingerPrint

type FingerPrint struct {
	Jenkins *Jenkins
	Base    string
	Id      string
	Raw     *FingerPrintResponse
}

func (FingerPrint) GetInfo

func (FingerPrint) Poll

func (f FingerPrint) Poll(ctx context.Context) (int, error)

func (FingerPrint) Valid

func (f FingerPrint) Valid(ctx context.Context) (bool, error)

func (FingerPrint) ValidateForBuild

func (f FingerPrint) ValidateForBuild(ctx context.Context, filename string, build *Build) (bool, error)

type FingerPrintResponse

type FingerPrintResponse struct {
	FileName string `json:"fileName"`
	Hash     string `json:"hash"`
	Original struct {
		Name   string
		Number int64
	} `json:"original"`
	Timestamp int64 `json:"timestamp"`
	Usage     []struct {
		Name   string `json:"name"`
		Ranges struct {
			Ranges []struct {
				End   int64 `json:"end"`
				Start int64 `json:"start"`
			} `json:"ranges"`
		} `json:"ranges"`
	} `json:"usage"`
}

type Folder

type Folder struct {
	Raw     *FolderResponse
	Jenkins *Jenkins
	Base    string
}

func (*Folder) Create

func (f *Folder) Create(ctx context.Context, name string) (*Folder, error)

func (*Folder) GetName

func (f *Folder) GetName() string

func (*Folder) Poll

func (f *Folder) Poll(ctx context.Context) (int, error)

type FolderResponse

type FolderResponse struct {
	Actions     []generalObj
	Description string     `json:"description"`
	DisplayName string     `json:"displayName"`
	Name        string     `json:"name"`
	URL         string     `json:"url"`
	Jobs        []InnerJob `json:"jobs"`
	PrimaryView *ViewData  `json:"primaryView"`
	Views       []ViewData `json:"views"`
}

type History

type History struct {
	BuildDisplayName string
	BuildNumber      int
	BuildStatus      string
	BuildTimestamp   int64
}

type InnerJob

type InnerJob struct {
	Class string `json:"_class"`
	Name  string `json:"name"`
	Url   string `json:"url"`
	Color string `json:"color"`
}

type Jenkins

type Jenkins struct {
	Server    string
	Version   string
	Raw       *ExecutorResponse
	Requester *Requester
}

func CreateJenkins

func CreateJenkins(client *http.Client, base string, auth ...interface{}) *Jenkins

Creates a new Jenkins Instance Optional parameters are: client, username, password or token After creating an instance call init method.

func (*Jenkins) BuildJob

func (j *Jenkins) BuildJob(ctx context.Context, name string, params map[string]string) (int64, error)

Invoke a job. First parameter job name, second parameter is optional Build parameters. Returns queue id

func (*Jenkins) CopyJob

func (j *Jenkins) CopyJob(ctx context.Context, copyFrom string, newName string) (*Job, error)

Create a copy of a job. First parameter Name of the job to copy from, Second parameter new job name.

func (*Jenkins) CreateFolder

func (j *Jenkins) CreateFolder(ctx context.Context, name string, parents ...string) (*Folder, error)

Create a new folder This folder can be nested in other parent folders Example: jenkins.CreateFolder("newFolder", "grandparentFolder", "parentFolder")

func (*Jenkins) CreateJob

func (j *Jenkins) CreateJob(ctx context.Context, config string, options ...interface{}) (*Job, error)

Create a new job from config File Method takes XML string as first parameter, and if the name is not specified in the config file takes name as string as second parameter e.g jenkins.CreateJob("<config></config>","newJobName")

func (*Jenkins) CreateJobInFolder

func (j *Jenkins) CreateJobInFolder(ctx context.Context, config string, jobName string, parentIDs ...string) (*Job, error)

Create a new job in the folder Example: jenkins.CreateJobInFolder("<config></config>", "newJobName", "myFolder", "parentFolder")

func (*Jenkins) CreateNode

func (j *Jenkins) CreateNode(ctx context.Context, name string, numExecutors int, description string, remoteFS string, label string, options ...interface{}) (*Node, error)

Create a new Node Can be JNLPLauncher or SSHLauncher Example : jenkins.CreateNode("nodeName", 1, "Description", "/var/lib/jenkins", "jdk8 docker", map[string]string{"method": "JNLPLauncher"}) By Default JNLPLauncher is created Multiple labels should be separated by blanks

func (*Jenkins) CreateUser

func (j *Jenkins) CreateUser(ctx context.Context, userName, password, fullName, email string) (User, error)

CreateUser creates a new Jenkins account

func (*Jenkins) CreateView

func (j *Jenkins) CreateView(ctx context.Context, name string, viewType string) (*View, error)

Create View First Parameter - name of the View Second parameter - Type Possible Types:

gojenkins.LIST_VIEW
gojenkins.NESTED_VIEW
gojenkins.MY_VIEW
gojenkins.DASHBOARD_VIEW
gojenkins.PIPELINE_VIEW

Example: jenkins.CreateView("newView",gojenkins.LIST_VIEW)

func (*Jenkins) DeleteJob

func (j *Jenkins) DeleteJob(ctx context.Context, name string) (bool, error)

Delete a job.

func (*Jenkins) DeleteNode

func (j *Jenkins) DeleteNode(ctx context.Context, name string) (bool, error)

Delete a Jenkins slave node

func (*Jenkins) DeleteUser

func (j *Jenkins) DeleteUser(ctx context.Context, userName string) error

DeleteUser deletes a Jenkins account

func (*Jenkins) GenerateAPIToken

func (j *Jenkins) GenerateAPIToken(ctx context.Context, tokenName string) (APIToken, error)

GenerateAPIToken creates a new API token for the Jenkins client user

func (*Jenkins) GetAllBuildIds

func (j *Jenkins) GetAllBuildIds(ctx context.Context, job string) ([]JobBuild, error)

Get all builds Numbers and URLS for a specific job. There are only build IDs here, To get all the other info of the build use jenkins.GetBuild(job,buildNumber) or job.GetBuild(buildNumber)

func (*Jenkins) GetAllJobNames

func (j *Jenkins) GetAllJobNames(ctx context.Context) ([]InnerJob, error)

Get Only Array of Job Names, Color, URL Does not query each single Job.

func (*Jenkins) GetAllJobs

func (j *Jenkins) GetAllJobs(ctx context.Context) ([]*Job, error)

Get All Possible Job Objects. Each job will be queried.

func (*Jenkins) GetAllNodes

func (j *Jenkins) GetAllNodes(ctx context.Context) ([]*Node, error)

func (*Jenkins) GetAllViews

func (j *Jenkins) GetAllViews(ctx context.Context) ([]*View, error)

func (*Jenkins) GetArtifactData

func (j *Jenkins) GetArtifactData(ctx context.Context, id string) (*FingerPrintResponse, error)

Get Artifact data by Hash

func (*Jenkins) GetBuild

func (j *Jenkins) GetBuild(ctx context.Context, jobName string, number int64) (*Build, error)

func (*Jenkins) GetBuildFromQueueID

func (j *Jenkins) GetBuildFromQueueID(ctx context.Context, job *Job, queueid int64) (*Build, error)

A task in queue will be assigned a build number in a job after a few seconds. this function will return the build object.

func (*Jenkins) GetFolder

func (j *Jenkins) GetFolder(ctx context.Context, id string, parents ...string) (*Folder, error)

func (*Jenkins) GetJob

func (j *Jenkins) GetJob(ctx context.Context, id string, parentIDs ...string) (*Job, error)

func (*Jenkins) GetJobObj

func (j *Jenkins) GetJobObj(ctx context.Context, name string) *Job

Get a job object

func (*Jenkins) GetLabel

func (j *Jenkins) GetLabel(ctx context.Context, name string) (*Label, error)

func (*Jenkins) GetNode

func (j *Jenkins) GetNode(ctx context.Context, name string) (*Node, error)

func (*Jenkins) GetPlugins

func (j *Jenkins) GetPlugins(ctx context.Context, depth int) (*Plugins, error)

Returns the list of all plugins installed on the Jenkins server. You can supply depth parameter, to limit how much data is returned.

func (*Jenkins) GetQueue

func (j *Jenkins) GetQueue(ctx context.Context) (*Queue, error)

Returns a Queue

func (*Jenkins) GetQueueItem

func (j *Jenkins) GetQueueItem(ctx context.Context, id int64) (*Task, error)

GetQueueItem returns a single queue Task

func (*Jenkins) GetQueueUrl

func (j *Jenkins) GetQueueUrl() string

func (*Jenkins) GetSubJob

func (j *Jenkins) GetSubJob(ctx context.Context, parentId string, childId string) (*Job, error)

func (*Jenkins) GetView

func (j *Jenkins) GetView(ctx context.Context, name string) (*View, error)

func (*Jenkins) HasPlugin

func (j *Jenkins) HasPlugin(ctx context.Context, name string) (*Plugin, error)

Check if the plugin is installed on the server. Depth level 1 is used. If you need to go deeper, you can use GetPlugins, and iterate through them.

func (*Jenkins) Info

func (j *Jenkins) Info(ctx context.Context) (*ExecutorResponse, error)

Get Basic Information About Jenkins

func (*Jenkins) Init

func (j *Jenkins) Init(ctx context.Context) (*Jenkins, error)

Init Method. Should be called after creating a Jenkins Instance. e.g jenkins,err := CreateJenkins("url").Init() HTTP Client is set here, Connection to jenkins is tested here.

func (*Jenkins) InstallPlugin

func (j *Jenkins) InstallPlugin(ctx context.Context, name string, version string) error

InstallPlugin with given version and name

func (*Jenkins) Poll

func (j *Jenkins) Poll(ctx context.Context) (int, error)

func (*Jenkins) RenameJob

func (j *Jenkins) RenameJob(ctx context.Context, job string, name string) *Job

Rename a job. First parameter job old name, Second parameter job new name.

func (*Jenkins) RevokeAPIToken

func (j *Jenkins) RevokeAPIToken(ctx context.Context, tokenUuid string) error

RevokeAPIToken revokes an API token

func (*Jenkins) RevokeAllAPITokens

func (j *Jenkins) RevokeAllAPITokens(ctx context.Context) error

RevokeAllAPITokens revokes all API tokens for the Jenkins client user

func (*Jenkins) SafeRestart

func (j *Jenkins) SafeRestart(ctx context.Context) error

SafeRestart jenkins, restart will be done when there are no jobs running

func (*Jenkins) UninstallPlugin

func (j *Jenkins) UninstallPlugin(ctx context.Context, name string) error

UninstallPlugin plugin otherwise returns error

func (*Jenkins) UpdateJob

func (j *Jenkins) UpdateJob(ctx context.Context, job string, config string) *Job

Update a job. If a job is exist, update its config

func (*Jenkins) ValidateFingerPrint

func (j *Jenkins) ValidateFingerPrint(ctx context.Context, id string) (bool, error)

Verify FingerPrint

type Job

type Job struct {
	Raw     *JobResponse
	Jenkins *Jenkins
	Base    string
}

func (*Job) Copy

func (j *Job) Copy(ctx context.Context, destinationName string) (*Job, error)

func (*Job) Create

func (j *Job) Create(ctx context.Context, config string, qr ...interface{}) (*Job, error)

func (*Job) Delete

func (j *Job) Delete(ctx context.Context) (bool, error)

func (*Job) Disable

func (j *Job) Disable(ctx context.Context) (bool, error)

func (*Job) Enable

func (j *Job) Enable(ctx context.Context) (bool, error)

func (*Job) GetAllBuildIds

func (j *Job) GetAllBuildIds(ctx context.Context) ([]JobBuild, error)

Returns All Builds with Number and URL

func (*Job) GetBuild

func (j *Job) GetBuild(ctx context.Context, id int64) (*Build, error)

func (*Job) GetBuildsFields

func (j *Job) GetBuildsFields(ctx context.Context, fields []string, custom interface{}) error

func (*Job) GetConfig

func (j *Job) GetConfig(ctx context.Context) (string, error)

func (*Job) GetDescription

func (j *Job) GetDescription() string

func (*Job) GetDetails

func (j *Job) GetDetails() *JobResponse

func (*Job) GetDownstreamJobs

func (j *Job) GetDownstreamJobs(ctx context.Context) ([]*Job, error)

func (*Job) GetDownstreamJobsMetadata

func (j *Job) GetDownstreamJobsMetadata() []InnerJob

func (*Job) GetFirstBuild

func (j *Job) GetFirstBuild(ctx context.Context) (*Build, error)

func (*Job) GetInnerJob

func (j *Job) GetInnerJob(ctx context.Context, id string) (*Job, error)

func (*Job) GetInnerJobs

func (j *Job) GetInnerJobs(ctx context.Context) ([]*Job, error)

func (*Job) GetInnerJobsMetadata

func (j *Job) GetInnerJobsMetadata() []InnerJob

func (*Job) GetLastBuild

func (j *Job) GetLastBuild(ctx context.Context) (*Build, error)

func (*Job) GetLastCompletedBuild

func (j *Job) GetLastCompletedBuild(ctx context.Context) (*Build, error)

func (*Job) GetLastFailedBuild

func (j *Job) GetLastFailedBuild(ctx context.Context) (*Build, error)

func (*Job) GetLastStableBuild

func (j *Job) GetLastStableBuild(ctx context.Context) (*Build, error)

func (*Job) GetLastSuccessfulBuild

func (j *Job) GetLastSuccessfulBuild(ctx context.Context) (*Build, error)

func (*Job) GetName

func (j *Job) GetName() string

func (*Job) GetParameters

func (j *Job) GetParameters(ctx context.Context) ([]ParameterDefinition, error)

func (*Job) GetPipelineRun

func (job *Job) GetPipelineRun(ctx context.Context, id string) (pr *PipelineRun, err error)

func (*Job) GetPipelineRuns

func (job *Job) GetPipelineRuns(ctx context.Context) (pr []PipelineRun, err error)

func (*Job) GetUpstreamJobs

func (j *Job) GetUpstreamJobs(ctx context.Context) ([]*Job, error)

func (*Job) GetUpstreamJobsMetadata

func (j *Job) GetUpstreamJobsMetadata() []InnerJob

func (*Job) HasQueuedBuild

func (j *Job) HasQueuedBuild()

func (*Job) History

func (j *Job) History(ctx context.Context) ([]*History, error)

func (*Job) Invoke

func (j *Job) Invoke(ctx context.Context, files []string, skipIfRunning bool, params map[string]string, cause string, securityToken string) (bool, error)

func (*Job) InvokeSimple

func (j *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64, error)

func (*Job) IsEnabled

func (j *Job) IsEnabled(ctx context.Context) (bool, error)

func (*Job) IsQueued

func (j *Job) IsQueued(ctx context.Context) (bool, error)

func (*Job) IsRunning

func (j *Job) IsRunning(ctx context.Context) (bool, error)

func (*Job) Poll

func (j *Job) Poll(ctx context.Context) (int, error)

func (*Job) Rename

func (j *Job) Rename(ctx context.Context, name string) (bool, error)

func (*Job) UpdateConfig

func (j *Job) UpdateConfig(ctx context.Context, config string) error

type JobBuild

type JobBuild struct {
	Number int64
	URL    string
}

type JobResponse

type JobResponse struct {
	Class              string `json:"_class"`
	Actions            []generalObj
	Buildable          bool `json:"buildable"`
	Builds             []JobBuild
	Color              string      `json:"color"`
	ConcurrentBuild    bool        `json:"concurrentBuild"`
	Description        string      `json:"description"`
	DisplayName        string      `json:"displayName"`
	DisplayNameOrNull  interface{} `json:"displayNameOrNull"`
	DownstreamProjects []InnerJob  `json:"downstreamProjects"`
	FirstBuild         JobBuild
	FullName           string `json:"fullName"`
	FullDisplayName    string `json:"fullDisplayName"`
	HealthReport       []struct {
		Description   string `json:"description"`
		IconClassName string `json:"iconClassName"`
		IconUrl       string `json:"iconUrl"`
		Score         int64  `json:"score"`
	} `json:"healthReport"`
	InQueue               bool     `json:"inQueue"`
	KeepDependencies      bool     `json:"keepDependencies"`
	LastBuild             JobBuild `json:"lastBuild"`
	LastCompletedBuild    JobBuild `json:"lastCompletedBuild"`
	LastFailedBuild       JobBuild `json:"lastFailedBuild"`
	LastStableBuild       JobBuild `json:"lastStableBuild"`
	LastSuccessfulBuild   JobBuild `json:"lastSuccessfulBuild"`
	LastUnstableBuild     JobBuild `json:"lastUnstableBuild"`
	LastUnsuccessfulBuild JobBuild `json:"lastUnsuccessfulBuild"`
	Name                  string   `json:"name"`
	NextBuildNumber       int64    `json:"nextBuildNumber"`
	Property              []struct {
		ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
	} `json:"property"`
	QueueItem        interface{} `json:"queueItem"`
	Scm              struct{}    `json:"scm"`
	UpstreamProjects []InnerJob  `json:"upstreamProjects"`
	URL              string      `json:"url"`
	Jobs             []InnerJob  `json:"jobs"`
	PrimaryView      *ViewData   `json:"primaryView"`
	Views            []ViewData  `json:"views"`
}

type Label

type Label struct {
	Raw     *LabelResponse
	Jenkins *Jenkins
	Base    string
}

func (*Label) GetName

func (l *Label) GetName() string

func (*Label) GetNodes

func (l *Label) GetNodes() []LabelNode

func (*Label) Poll

func (l *Label) Poll(ctx context.Context) (int, error)

type LabelNode

type LabelNode struct {
	NodeName        string `json:"nodeName"`
	NodeDescription string `json:"nodeDescription"`
	NumExecutors    int64  `json:"numExecutors"`
	Mode            string `json:"mode"`
	Class           string `json:"_class"`
}

type LabelResponse

type LabelResponse struct {
	Name           string      `json:"name"`
	Description    string      `json:"description"`
	Nodes          []LabelNode `json:"nodes"`
	Offline        bool        `json:"offline"`
	IdleExecutors  int64       `json:"idleExecutors"`
	BusyExecutors  int64       `json:"busyExecutors"`
	TotalExecutors int64       `json:"totalExecutors"`
}

type MODE

type MODE string
const (
	NORMAL    MODE = "NORMAL"
	EXCLUSIVE      = "EXCLUSIVE"
)

type Node

type Node struct {
	Raw     *NodeResponse
	Jenkins *Jenkins
	Base    string
}

func (*Node) Delete

func (n *Node) Delete(ctx context.Context) (bool, error)

func (*Node) Disconnect

func (n *Node) Disconnect(ctx context.Context) (int, error)

func (*Node) GetLogText

func (n *Node) GetLogText(ctx context.Context) (string, error)

func (*Node) GetName

func (n *Node) GetName() string

func (*Node) Info

func (n *Node) Info(ctx context.Context) (*NodeResponse, error)

func (*Node) IsIdle

func (n *Node) IsIdle(ctx context.Context) (bool, error)

func (*Node) IsJnlpAgent

func (n *Node) IsJnlpAgent(ctx context.Context) (bool, error)

func (*Node) IsOnline

func (n *Node) IsOnline(ctx context.Context) (bool, error)

func (*Node) IsTemporarilyOffline

func (n *Node) IsTemporarilyOffline(ctx context.Context) (bool, error)

func (*Node) LaunchNodeBySSH

func (n *Node) LaunchNodeBySSH(ctx context.Context) (int, error)

func (*Node) Poll

func (n *Node) Poll(ctx context.Context) (int, error)

func (*Node) SetOffline

func (n *Node) SetOffline(ctx context.Context, options ...interface{}) (bool, error)

func (*Node) SetOnline

func (n *Node) SetOnline(ctx context.Context) (bool, error)

func (*Node) ToggleTemporarilyOffline

func (n *Node) ToggleTemporarilyOffline(ctx context.Context, options ...interface{}) (bool, error)

type NodeResponse

type NodeResponse struct {
	Class       string        `json:"_class"`
	Actions     []interface{} `json:"actions"`
	DisplayName string        `json:"displayName"`
	Executors   []struct {
		CurrentExecutable struct {
			Number    int    `json:"number"`
			URL       string `json:"url"`
			SubBuilds []struct {
				Abort             bool        `json:"abort"`
				Build             interface{} `json:"build"`
				BuildNumber       int         `json:"buildNumber"`
				Duration          string      `json:"duration"`
				Icon              string      `json:"icon"`
				JobName           string      `json:"jobName"`
				ParentBuildNumber int         `json:"parentBuildNumber"`
				ParentJobName     string      `json:"parentJobName"`
				PhaseName         string      `json:"phaseName"`
				Result            string      `json:"result"`
				Retry             bool        `json:"retry"`
				URL               string      `json:"url"`
			} `json:"subBuilds"`
		} `json:"currentExecutable"`
	} `json:"executors"`
	Icon                string   `json:"icon"`
	IconClassName       string   `json:"iconClassName"`
	Idle                bool     `json:"idle"`
	JnlpAgent           bool     `json:"jnlpAgent"`
	LaunchSupported     bool     `json:"launchSupported"`
	LoadStatistics      struct{} `json:"loadStatistics"`
	ManualLaunchAllowed bool     `json:"manualLaunchAllowed"`
	MonitorData         struct {
		Hudson_NodeMonitors_ArchitectureMonitor interface{} `json:"hudson.node_monitors.ArchitectureMonitor"`
		Hudson_NodeMonitors_ClockMonitor        interface{} `json:"hudson.node_monitors.ClockMonitor"`
		Hudson_NodeMonitors_DiskSpaceMonitor    interface{} `json:"hudson.node_monitors.DiskSpaceMonitor"`
		Hudson_NodeMonitors_ResponseTimeMonitor struct {
			Average int64 `json:"average"`
		} `json:"hudson.node_monitors.ResponseTimeMonitor"`
		Hudson_NodeMonitors_SwapSpaceMonitor      interface{} `json:"hudson.node_monitors.SwapSpaceMonitor"`
		Hudson_NodeMonitors_TemporarySpaceMonitor interface{} `json:"hudson.node_monitors.TemporarySpaceMonitor"`
	} `json:"monitorData"`
	NumExecutors       int64         `json:"numExecutors"`
	Offline            bool          `json:"offline"`
	OfflineCause       struct{}      `json:"offlineCause"`
	OfflineCauseReason string        `json:"offlineCauseReason"`
	OneOffExecutors    []interface{} `json:"oneOffExecutors"`
	TemporarilyOffline bool          `json:"temporarilyOffline"`
}

type ParameterDefinition

type ParameterDefinition struct {
	DefaultParameterValue struct {
		Name  string      `json:"name"`
		Value interface{} `json:"value"`
	} `json:"defaultParameterValue"`
	Description string `json:"description"`
	Name        string `json:"name"`
	Type        string `json:"type"`
}

type PipelineArtifact

type PipelineArtifact struct {
	ID   string
	Name string
	Path string
	URL  string
	// contains filtered or unexported fields
}

type PipelineInputAction

type PipelineInputAction struct {
	ID         string
	Message    string
	ProceedURL string
	AbortURL   string
}

type PipelineNode

type PipelineNode struct {
	Run            *PipelineRun
	Base           string
	URLs           map[string]map[string]string `json:"_links"`
	ID             string
	Name           string
	Status         string
	StartTime      int64 `json:"startTimeMillis"`
	Duration       int64 `json:"durationMillis"`
	StageFlowNodes []PipelineNode
	ParentNodes    []int64
}

func (*PipelineNode) GetLog

func (node *PipelineNode) GetLog(ctx context.Context) (log *PipelineNodeLog, err error)

type PipelineNodeLog

type PipelineNodeLog struct {
	NodeID     string
	NodeStatus string
	Length     int64
	HasMore    bool
	Text       string
	ConsoleURL string
}

type PipelineRun

type PipelineRun struct {
	Job       *Job
	Base      string
	URLs      map[string]map[string]string `json:"_links"`
	ID        string
	Name      string
	Status    string
	StartTime int64 `json:"startTimeMillis"`
	EndTime   int64 `json:"endTimeMillis"`
	Duration  int64 `json:"durationMillis"`
	Stages    []PipelineNode
}

func (*PipelineRun) AbortInput

func (pr *PipelineRun) AbortInput(ctx context.Context) (bool, error)

func (*PipelineRun) GetArtifacts

func (pr *PipelineRun) GetArtifacts(ctx context.Context) (artifacts []PipelineArtifact, err error)

func (*PipelineRun) GetNode

func (pr *PipelineRun) GetNode(ctx context.Context, id string) (node *PipelineNode, err error)

func (*PipelineRun) GetPendingInputActions

func (pr *PipelineRun) GetPendingInputActions(ctx context.Context) (PIAs []PipelineInputAction, err error)

func (*PipelineRun) ProceedInput

func (pr *PipelineRun) ProceedInput(ctx context.Context) (bool, error)

type Plugin

type Plugin struct {
	Active        bool        `json:"active"`
	BackupVersion interface{} `json:"backupVersion"`
	Bundled       bool        `json:"bundled"`
	Deleted       bool        `json:"deleted"`
	Dependencies  []struct {
		Optional  string `json:"optional"`
		ShortName string `json:"shortname"`
		Version   string `json:"version"`
	} `json:"dependencies"`
	Downgradable        bool   `json:"downgradable"`
	Enabled             bool   `json:"enabled"`
	HasUpdate           bool   `json:"hasUpdate"`
	LongName            string `json:"longName"`
	Pinned              bool   `json:"pinned"`
	ShortName           string `json:"shortName"`
	SupportsDynamicLoad string `json:"supportsDynamicLoad"`
	URL                 string `json:"url"`
	Version             string `json:"version"`
}

type PluginResponse

type PluginResponse struct {
	Plugins []Plugin `json:"plugins"`
}

type Plugins

type Plugins struct {
	Jenkins *Jenkins
	Raw     *PluginResponse
	Base    string
	Depth   int
}

func (*Plugins) Contains

func (p *Plugins) Contains(name string) *Plugin

func (*Plugins) Count

func (p *Plugins) Count() int

func (*Plugins) Poll

func (p *Plugins) Poll(ctx context.Context) (int, error)

type PrivateKey

type PrivateKey struct {
	Value string `xml:"privateKey"`
	Class string `xml:"class,attr"`
}

PrivateKey used in SSHCredentials type, type can be either: KeySourceDirectEntryType - then value should be text with secret KeySourceOnMasterType - then value should be path on master jenkins where secret is stored

type PrivateKeyFile

type PrivateKeyFile struct {
	Value string `xml:"privateKeyFile"`
	Class string `xml:"class,attr"`
}

type Queue

type Queue struct {
	Jenkins *Jenkins
	Raw     *queueResponse
	Base    string
}

func (*Queue) CancelTask

func (q *Queue) CancelTask(ctx context.Context, id int64) (bool, error)

func (*Queue) GetTaskById

func (q *Queue) GetTaskById(id int64) *Task

func (*Queue) GetTasksForJob

func (q *Queue) GetTasksForJob(name string) []*Task

func (*Queue) Poll

func (q *Queue) Poll(ctx context.Context) (int, error)

func (*Queue) Tasks

func (q *Queue) Tasks() []*Task

type Requester

type Requester struct {
	Base      string
	BasicAuth *BasicAuth
	Client    *http.Client
	CACert    []byte
	SslVerify bool
}

func (*Requester) Do

func (r *Requester) Do(ctx context.Context, ar *APIRequest, responseStruct interface{}, options ...interface{}) (*http.Response, error)

func (*Requester) Get

func (r *Requester) Get(ctx context.Context, endpoint string, responseStruct interface{}, querystring map[string]string) (*http.Response, error)

func (*Requester) GetJSON

func (r *Requester) GetJSON(ctx context.Context, endpoint string, responseStruct interface{}, query map[string]string) (*http.Response, error)

func (*Requester) GetXML

func (r *Requester) GetXML(ctx context.Context, endpoint string, responseStruct interface{}, query map[string]string) (*http.Response, error)

func (*Requester) Post

func (r *Requester) Post(ctx context.Context, endpoint string, payload io.Reader, responseStruct interface{}, querystring map[string]string) (*http.Response, error)

func (*Requester) PostFiles

func (r *Requester) PostFiles(ctx context.Context, endpoint string, payload io.Reader, responseStruct interface{}, querystring map[string]string, files []string) (*http.Response, error)

func (*Requester) PostJSON

func (r *Requester) PostJSON(ctx context.Context, endpoint string, payload io.Reader, responseStruct interface{}, querystring map[string]string) (*http.Response, error)

func (*Requester) PostXML

func (r *Requester) PostXML(ctx context.Context, endpoint string, xml string, responseStruct interface{}, querystring map[string]string) (*http.Response, error)

func (*Requester) ReadJSONResponse

func (r *Requester) ReadJSONResponse(response *http.Response, responseStruct interface{}) (*http.Response, error)

func (*Requester) ReadRawResponse

func (r *Requester) ReadRawResponse(response *http.Response, responseStruct interface{}) (*http.Response, error)

func (*Requester) SetClient

func (r *Requester) SetClient(client *http.Client) *Requester

func (*Requester) SetCrumb

func (r *Requester) SetCrumb(ctx context.Context, ar *APIRequest) error

type SSHCredentials

type SSHCredentials struct {
	XMLName          xml.Name    `xml:"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"`
	ID               string      `xml:"id"`
	Scope            string      `xml:"scope"`
	Username         string      `xml:"username"`
	Description      string      `xml:"description,omitempty"`
	PrivateKeySource interface{} `xml:"privateKeySource"`
	Passphrase       string      `xml:"passphrase,omitempty"`
}

SSHCredentials store credentials for ssh keys.

type StringCredentials

type StringCredentials struct {
	XMLName     xml.Name `xml:"org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl"`
	ID          string   `xml:"id"`
	Scope       string   `xml:"scope"`
	Description string   `xml:"description"`
	Secret      string   `xml:"secret"`
}

StringCredentials store only secret text

type Task

type Task struct {
	Raw     *taskResponse
	Jenkins *Jenkins
	Queue   *Queue
	Base    string
}

func (*Task) Cancel

func (t *Task) Cancel(ctx context.Context) (bool, error)

func (*Task) GetCauses

func (t *Task) GetCauses() []map[string]interface{}

func (*Task) GetJob

func (t *Task) GetJob(ctx context.Context) (*Job, error)

func (*Task) GetParameters

func (t *Task) GetParameters() []parameter

func (*Task) GetWhy

func (t *Task) GetWhy() string

func (*Task) Poll

func (t *Task) Poll(ctx context.Context) (int, error)

type TestResult

type TestResult struct {
	Duration  float64 `json:"duration"`
	Empty     bool    `json:"empty"`
	FailCount int64   `json:"failCount"`
	PassCount int64   `json:"passCount"`
	SkipCount int64   `json:"skipCount"`
	Suites    []struct {
		Cases []struct {
			Age             int64       `json:"age"`
			ClassName       string      `json:"className"`
			Duration        float64     `json:"duration"`
			ErrorDetails    interface{} `json:"errorDetails"`
			ErrorStackTrace interface{} `json:"errorStackTrace"`
			FailedSince     int64       `json:"failedSince"`
			Name            string      `json:"name"`
			Skipped         bool        `json:"skipped"`
			SkippedMessage  interface{} `json:"skippedMessage"`
			Status          string      `json:"status"`
			Stderr          interface{} `json:"stderr"`
			Stdout          interface{} `json:"stdout"`
		} `json:"cases"`
		Duration  float64     `json:"duration"`
		ID        interface{} `json:"id"`
		Name      string      `json:"name"`
		Stderr    interface{} `json:"stderr"`
		Stdout    interface{} `json:"stdout"`
		Timestamp interface{} `json:"timestamp"`
	} `json:"suites"`
}

type User

type User struct {
	Jenkins  *Jenkins
	UserName string
	FullName string
	Email    string
}

User is a Jenkins account

func (*User) Delete

func (u *User) Delete() error

Delete deletes a Jenkins account

type UsernameCredentials

type UsernameCredentials struct {
	XMLName     xml.Name `xml:"com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"`
	ID          string   `xml:"id"`
	Scope       string   `xml:"scope"`
	Description string   `xml:"description"`
	Username    string   `xml:"username"`
	Password    string   `xml:"password"`
}

UsernameCredentials struct representing credential for storing username-password pair

type View

type View struct {
	Raw     *ViewResponse
	Jenkins *Jenkins
	Base    string
}

func (*View) AddJob

func (v *View) AddJob(ctx context.Context, name string) (bool, error)

Returns True if successfully added Job, otherwise false

func (*View) DeleteJob

func (v *View) DeleteJob(ctx context.Context, name string) (bool, error)

Returns True if successfully deleted Job, otherwise false

func (*View) GetDescription

func (v *View) GetDescription() string

func (*View) GetJobs

func (v *View) GetJobs() []InnerJob

func (*View) GetName

func (v *View) GetName() string

func (*View) GetUrl

func (v *View) GetUrl() string

func (*View) Poll

func (v *View) Poll(ctx context.Context) (int, error)

type ViewData

type ViewData struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

type ViewResponse

type ViewResponse struct {
	Description string        `json:"description"`
	Jobs        []InnerJob    `json:"jobs"`
	Name        string        `json:"name"`
	Property    []interface{} `json:"property"`
	URL         string        `json:"url"`
}

Jump to

Keyboard shortcuts

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