https://github.com/joelee2012/go-jenkins
Go client library for Jenkins API
https://github.com/joelee2012/go-jenkins
go-jenkins jenkins jenkinsapi restapi
Last synced: about 1 month ago
JSON representation
Go client library for Jenkins API
- Host: GitHub
- URL: https://github.com/joelee2012/go-jenkins
- Owner: joelee2012
- License: apache-2.0
- Created: 2021-04-01T09:33:23.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-29T09:36:27.000Z (6 months ago)
- Last Synced: 2025-02-14T13:18:28.262Z (3 months ago)
- Topics: go-jenkins, jenkins, jenkinsapi, restapi
- Language: Go
- Homepage:
- Size: 199 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


[](https://codecov.io/gh/joelee2012/go-jenkins)
# go-jenkins
[Golang](https://golang.org/) client library for accessing [Jenkins API](https://www.jenkins.io/doc/book/using/remote-access-api/).
> Ported from [api4jenkins](https://github.com/joelee2012/api4jenkins>), a [Python3](https://www.python.org/) client library for [Jenkins API](https://www.jenkins.io/doc/book/using/remote-access-api/).# Features
This API client package covers most of the existing Jenkins API calls and is updated regularly to add new and/or missing endpoints.Currently, the following are supported:
- Job
- Build
- Credential
- View
- Queue
- Node# Usage
```go
import "github.com/joelee2012/go-jenkins"
```## Example
```go
package mainimport (
"log"
"time""github.com/joelee2012/go-jenkins"
)func main() {
// Construct new client
client, err := jenkins.NewClient("http://localhost:8080/", "admin", "1234")
if err != nil {
log.Fatalln(err)
}
xml := `
#!groovy
pipeline {
agent any
stages {
stage('build'){
steps{
sh 'echo $JENKINS_VERSION'
}
}
}
}
true
false
`
// create jenkins job
if err := client.CreateJob("pipeline", xml); err != nil {
log.Fatalln(err)
}
// Build Job and get BuildItem
qitem, err := client.BuildJob("pipeline", nil)
if err != nil {
log.Fatalln(err)
}
var build *Build
for {
time.Sleep(1 * time.Second)
build, err = qitem.GetBuild()
if err != nil {
log.Fatalln(err)
}
if build != nil {
break
}
}
// tail the build log to end
build.LoopProgressiveLog("text", func(line string) error {
log.Println(line)
time.Sleep(1 * time.Second)
return nil
})
}
```# Documentation
See https://pkg.go.dev/github.com/joelee2012/go-jenkins