
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
gopkg.in/bndr/gojenkins.v1
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:
go get github.com/bndr/gojenkins
import "github.com/bndr/gojenkins"
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()
if err != nil {
panic("Something Went Wrong")
}
build, err := jenkins.GetJob("job_name")
if err != nil {
panic("Job Does Not Exist")
}
lastSuccessBuild, err := build.GetLastSuccessfulBuild()
if err != nil {
panic("Last SuccessBuild does not exist")
}
duration := lastSuccessBuild.GetDuration()
job, err := jenkins.GetJob("jobname")
if err != nil {
panic("Job does not exist")
}
job.Rename("SomeotherJobName")
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>`
j.CreateJob(configString, "someNewJobsName")
API Reference: https://godoc.org/github.com/bndr/gojenkins
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()
or if you don't need authentication:
jenkins, _ := gojenkins.CreateJenkins(nil, "http://localhost:8080/").Init()
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()
By default, gojenkins
will use the http.DefaultClient
if none is passed into the CreateJenkins()
function.
nodes := jenkins.GetAllNodes()
for _, node := range nodes {
// Fetch Node Data
node.Poll()
if node.IsOnline() {
fmt.Println("Node is Online")
}
}
jobName := "someJob"
builds, err := jenkins.GetAllBuildIds(jobName)
if err != nil {
panic(err)
}
for _, build := range builds {
buildId := build.Number
data, err := jenkins.GetBuild(jobName, buildId)
if err != nil {
panic(err)
}
if "SUCCESS" == data.GetResult() {
fmt.Println("This build succeeded")
}
}
// Get Last Successful/Failed/Stable Build for a Job
job, err := jenkins.GetJob("someJob")
if err != nil {
panic(err)
}
job.GetLastSuccessfulBuild()
job.GetLastStableBuild()
tasks := jenkins.GetQueue()
for _, task := range tasks {
fmt.Println(task.GetWhy())
}
view, err := jenkins.CreateView("test_view", gojenkins.LIST_VIEW)
if err != nil {
panic(err)
}
status, err := view.AddJob("jobName")
if status != nil {
fmt.Println("Job has been added to view")
}
// Create parent folder
pFolder, err := jenkins.CreateFolder("parentFolder")
if err != nil {
panic(err)
}
// Create child folder in parent folder
cFolder, err := jenkins.CreateFolder("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(configString, "jobInFolder", pFolder.GetName(), cFolder.GetName())
if err != nil {
panic(err)
}
if job != nil {
fmt.Println("Job has been created in child folder")
}
job, _ := jenkins.GetJob("job")
build, _ := job.GetBuild(1)
artifacts := build.GetArtifacts()
for _, a := range artifacts {
a.SaveToDir("/tmp")
}
job, _ := jenkins.GetJob("job")
job.Poll()
build, _ := job.getBuild(1)
build.Poll()
go test
All Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.
Although the basic features are implemented there are many optional features that are on the todo list.
Apache License 2.0
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.