Skip to content

Commit

Permalink
License Update, Package rename
Browse files Browse the repository at this point in the history
  • Loading branch information
bndr committed Oct 31, 2014
1 parent 4d52183 commit c1c52b3
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

go:
- 1.2
- 1.3
- tip
install:
- go get github.com/stretchr/testify/assert
1 change: 1 addition & 0 deletions AUTHOR
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vadim Kravcenko 2014
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
go-jenkins
==========
# Jenkins API Client for Go

## 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.
* Validate Fingerprints of Artifacts
* Get Current Queue, Cancel Tasks
* etc.

## Installation

go get github.com/bndr/gojenkins

## Usage


## Examples

## Testing

## 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
* CLI Tool
* Rewrite some (all?) iterators with channels

## LICENSE

Apache License 2.0
16 changes: 15 additions & 1 deletion artifact.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"crypto/md5"
Expand Down
16 changes: 15 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gojenkins

const (
STATUS_FAIL = "FAIL"
Expand Down
16 changes: 15 additions & 1 deletion executor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

type executor struct {
Raw *executorResponse
Expand Down
16 changes: 15 additions & 1 deletion fingerprint.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

type Fingerprint struct {
Jenkins *Jenkins
Expand Down
60 changes: 31 additions & 29 deletions jenkins.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

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

import (
"crypto/tls"
"fmt"
"log"
"net/http"
"net/http/cookiejar"
Expand All @@ -11,16 +25,12 @@ import (
"strings"
)

// Basic Authentication
type BasicAuth struct {
Username string
Password string
}

type TokenAuth struct {
Username string
Token string
}

type Jenkins struct {
Server string
Version string
Expand All @@ -29,29 +39,29 @@ type Jenkins struct {
}

// Loggers

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

// Jenkins

// Init Method. Should be called after creating a Jenkins Instance.
// e.g jenkins := CreateJenkins("url").Init()
// HTTP Client is set here, Connection to jenkins is tested here.
func (j *Jenkins) Init() *Jenkins {
j.initLoggers()
// Skip SSL Verification?
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: !j.Requester.SslVerify},
}

cookies, _ := cookiejar.New(nil)

client := &http.Client{
Transport: tr,
Jar: cookies,
}
if j.Requester.Client == nil {
cookies, _ := cookiejar.New(nil)

client := &http.Client{
Transport: tr,
Jar: cookies,
}
j.Requester.Client = client
}

Expand Down Expand Up @@ -79,6 +89,7 @@ func (j *Jenkins) initLoggers() {
log.Ldate|log.Ltime|log.Lshortfile)
}

// Get Basic Information About Jenkins
func (j *Jenkins) Info() *executorResponse {
j.Requester.Do("GET", "/", nil, j.Raw, nil)
return j.Raw
Expand Down Expand Up @@ -222,7 +233,7 @@ func (j *Jenkins) GetAllJobs(preload bool) []*Job {
}

func (j *Jenkins) GetQueue() *Queue {
q := &Queue{Jenkins: j, Raw: new(queueResponse), Base: "/queue"}
q := &Queue{Jenkins: j, Raw: new(queueResponse), Base: j.GetQueueUrl()}
q.Poll()
return q
}
Expand Down Expand Up @@ -256,6 +267,9 @@ func (j *Jenkins) ValidateFingerPrint(id string) bool {
return false
}

// Creates a new Jenkins Instance
// Optional parameters are: username, password
// After creating an instance call init method.
func CreateJenkins(base string, auth ...interface{}) *Jenkins {
j := &Jenkins{}
if strings.HasSuffix(base, "/") {
Expand All @@ -268,15 +282,3 @@ func CreateJenkins(base string, auth ...interface{}) *Jenkins {
}
return j
}

func main() {
j := CreateJenkins("http://localhost:8080/", "admin", "admin").Init()

//fmt.Printf("%#v\n", j.GetJob("testJobName").Raw.Description)
job := j.GetJob("testjib")
ts := job.GetLastBuild()
ts.GetArtifacts()[0].Save("/tmp/tabulateFile")
fmt.Printf("%#v", j.GetPlugins(1).Contains("ldap"))
//fmt.Printf("%#v\n", job.GetLastBuild().Info())
// fmt.Printf("%#v", j.CreateNode("wat23s1131sssasd1121", 2, "description", "/f/vs/sa/"))
}
16 changes: 15 additions & 1 deletion job.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"bytes"
Expand Down
16 changes: 15 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

// Nodes

Expand Down
16 changes: 15 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"strconv"
Expand Down
16 changes: 15 additions & 1 deletion queue.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"strconv"
Expand Down
16 changes: 15 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package main
// Copyright 2014 Vadim Kravcenko
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package gojenkins

import (
"bytes"
Expand Down
5 changes: 2 additions & 3 deletions tests/jenkins_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main
package gojenkins

import "testing"
import "github.com/stretchr/testify/assert"


func TestGetAllJobs(t *testing.T) {
assert.Equal(t,true,true)
assert.Equal(t, true, false)
}

func TestGetSingleJob(t *testing.T) {
Expand Down
Loading

0 comments on commit c1c52b3

Please sign in to comment.