public class DiggerClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DiggerClient.DiggerClientBuilder |
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_BUILD_TIMEOUT |
Modifier and Type | Method and Description |
---|---|
BuildTriggerStatus |
build(String jobName)
Triggers a build for the given job and waits until it leaves the queue and actually starts.
|
BuildTriggerStatus |
build(String jobName,
long timeout)
Triggers a build for the given job and waits until it leaves the queue and actually starts.
|
BuildTriggerStatus |
build(String jobName,
long timeout,
Map<String,String> params)
Triggers a build for the given job and waits until it leaves the queue and actually starts.
|
static DiggerClient.DiggerClientBuilder |
builder() |
com.offbytwo.jenkins.model.BuildWithDetails |
cancelBuild(String jobName,
int buildNumber)
Cancel a build for a specific job
|
static DiggerClient |
createDefaultWithAuth(String url,
String user,
String password)
Create a client with defaults using provided url and credentials, with crumb flag turned off.
|
static DiggerClient |
createDefaultWithAuth(String url,
String user,
String password,
boolean crumbFlag)
Create a client with defaults using provided url and credentials, and specify if crumb is enabled on the Jenkins server.
|
void |
createJob(String name,
String gitRepo,
String gitBranch,
BuildDiscarder buildDiscarder)
Create new Digger job on Jenkins platform with build and binary cleanup
|
void |
createJob(String name,
String gitRepo,
String gitBranch,
BuildDiscarder buildDiscarder,
com.offbytwo.jenkins.model.credentials.Credential gitRepoCredential,
List<BuildParameter> buildParameters)
Create new parameterized Digger job on Jenkins platform
|
void |
deleteJob(String jobName,
String credentialId)
Delete the job from Jenkins server.
|
InputStream |
fetchArtifact(String jobName,
int buildNumber,
String artifactName)
Fetch artifacts urls for specific job and build number
|
com.offbytwo.jenkins.model.BuildWithDetails |
getBuildDetails(String jobName,
int buildNumber)
Get the details about a build.
|
List<com.offbytwo.jenkins.model.BuildWithDetails> |
getBuildHistory(String jobName)
Returns the build history for a job.
|
String |
getBuildLogs(String jobName,
int buildNumber)
Get build logs for specific job and build number
|
com.offbytwo.jenkins.JenkinsServer |
getJenkinsServer()
Expose the underline Jenkins Server client to allow perform other operations that may not be implemented by the jenkins digger client.
|
com.offbytwo.jenkins.model.JobWithDetails |
getJob(String name)
Get a Digger job on the Jenkins platform.
|
BuildTriggerStatus |
pollBuild(String jobName,
com.offbytwo.jenkins.model.QueueReference queueReference,
long timeout,
Map<String,String> params)
This method takes a QueueReference and polls to check if a build goes to the next available executor or gets cancelled or gets stuck on the queue for some other reason.
|
void |
saveArtifact(String jobName,
int buildNumber,
String artifactName,
File outputFile)
Save artifact for specified location for specific job, build number and artifact name.
|
void |
streamLogs(String jobName,
int buildNumber,
LogStreamingOptions options)
Streaming the build logs.
|
BuildTriggerStatus |
triggerBuild(String jobName,
Map<String,String> params)
Triggers a build for the given job.
|
void |
updateJob(String name,
String gitRepo,
String gitBranch,
BuildDiscarder buildDiscarder)
Update a Digger job on Jenkins platform
|
void |
updateJob(String name,
String gitRepo,
String gitBranch,
BuildDiscarder buildDiscarder,
com.offbytwo.jenkins.model.credentials.Credential gitRepoCredential,
List<BuildParameter> buildParameters)
Update parameterized Digger job on Jenkins platform.
|
public static final long DEFAULT_BUILD_TIMEOUT
public static DiggerClient createDefaultWithAuth(String url, String user, String password) throws DiggerClientException
This client will use the defaults for the services. This is perfectly fine for majorith of the cases.
url
- Jenkins urluser
- Jenkins userpassword
- Jenkins passwordDiggerClientException
- if something goes wrongpublic static DiggerClient createDefaultWithAuth(String url, String user, String password, boolean crumbFlag) throws DiggerClientException
url
- Jenkins urluser
- Jenkins userpassword
- Jenkins passwordcrumbFlag
- If CSRF Protection is enabled on the Jenkins serverDiggerClientException
- if something goes wrongpublic static DiggerClient.DiggerClientBuilder builder()
public void createJob(String name, String gitRepo, String gitBranch, BuildDiscarder buildDiscarder) throws DiggerClientException
name
- job name that can be used later to reference jobgitRepo
- git repository url (full git repository url. e.g git@github.com:wtrocki/helloworld-android-gradle.gitgitBranch
- git repository branch (default branch used to checkout source code)DiggerClientException
- if something goes wrongpublic void createJob(String name, String gitRepo, String gitBranch, BuildDiscarder buildDiscarder, com.offbytwo.jenkins.model.credentials.Credential gitRepoCredential, List<BuildParameter> buildParameters) throws DiggerClientException
name
- job name that can be used later to reference jobgitRepo
- git repository url (full git repository url. e.g git@github.com:wtrocki/helloworld-android-gradle.gitgitBranch
- git repository branch (default branch used to checkout source code)gitRepoCredential
- the credential that will be used to clone the repo.buildParameters
- list of parameters for a Jenkins parameterized build.DiggerClientException
- if something goes wrongpublic void updateJob(String name, String gitRepo, String gitBranch, BuildDiscarder buildDiscarder) throws DiggerClientException
name
- job name that can be used later to reference jobgitRepo
- git repository url (full git repository url. e.g git@github.com:wtrocki/helloworld-android-gradle.gitgitBranch
- git repository branch (default branch used to checkout source code)buildDiscarder
- BuildDiscarder instance. See BuildDiscarder
DiggerClientException
- if something goes wrongpublic void updateJob(String name, String gitRepo, String gitBranch, BuildDiscarder buildDiscarder, com.offbytwo.jenkins.model.credentials.Credential gitRepoCredential, List<BuildParameter> buildParameters) throws DiggerClientException
name
- job name that can be used later to reference jobgitRepo
- git repository url (full git repository url. e.g git@github.com:wtrocki/helloworld-android-gradle.gitgitBranch
- git repository branch (default branch used to checkout source code)buildDiscarder
- BuildDiscarder instance. See BuildDiscarder
gitRepoCredential
- the credential that will be used to clone the repobuildParameters
- list of parameters for a Jenkins parameterized build.DiggerClientException
- if something goes wrongpublic com.offbytwo.jenkins.model.JobWithDetails getJob(String name) throws DiggerClientException
name
- name of the job to getDiggerClientException
- if something goes wrongpublic BuildTriggerStatus build(String jobName, long timeout, Map<String,String> params) throws DiggerClientException
Jenkins puts the build requests in a queue and once there is a slave available, it starts building it and a build number is assigned to the build.
This method will block until there is a build number, or the given timeout period is passed. If the build is still in the queue
after the given timeout period, a BuildStatus
is returned with state BuildTriggerStatus.State#TIMED_OUT
.
Please note that timeout period is never meant to be very precise. It has the resolution of BuildService.DEFAULT_POLL_PERIOD
because
timeout is checked before every pull.
Similarly, BuildTriggerStatus.State#CANCELLED_IN_QUEUE
is returned if the build is cancelled on Jenkins side and
BuildTriggerStatus.State#STUCK_IN_QUEUE
is returned if the build is stuck.
jobName
- name of the job to trigger the buildtimeout
- how many milliseconds should this call block before returning BuildTriggerStatus.State#TIMED_OUT
.
Should be larger than BuildService.DEFAULT_FIRST_CHECK_DELAY
params
- build parameters to be sent to the Jenkins buildDiggerClientException
- if connection problems occur during connecting to Jenkinspublic BuildTriggerStatus build(String jobName, long timeout) throws DiggerClientException
Calls build(String, long, Map)
with a default timeout of DEFAULT_BUILD_TIMEOUT
and no build parameters.
jobName
- name of the jobtimeout
- how many milliseconds should this call block before returning BuildTriggerStatus.State#TIMED_OUT
.
Should be larger than BuildService.DEFAULT_FIRST_CHECK_DELAY
DiggerClientException
- if connection problems occur during connecting to Jenkinsbuild(String, long)
public BuildTriggerStatus triggerBuild(String jobName, Map<String,String> params) throws DiggerClientException
build(String, long, Map)
, this method returns immediately with the build status, which also has a queue reference in it to track the buildjobName
- name of the jobparams
- build parameters to be sent to the Jenkins buildDiggerClientException
- if connection problems occur during connecting to Jenkinspublic BuildTriggerStatus pollBuild(String jobName, com.offbytwo.jenkins.model.QueueReference queueReference, long timeout, Map<String,String> params) throws DiggerClientException
queueReference
- The queue referencejobName
- name of the jobtimeout
- params
- build parameters to be sent to the Jenkins buildDiggerClientException
- if connection problems occur during connecting to Jenkinspublic BuildTriggerStatus build(String jobName) throws DiggerClientException
Calls build(String, long, Map)
with a default timeout of DEFAULT_BUILD_TIMEOUT
and no build parameters.
jobName
- name of the jobDiggerClientException
- if connection problems occur during connecting to Jenkinsbuild(String, long)
public InputStream fetchArtifact(String jobName, int buildNumber, String artifactName) throws DiggerClientException
jobName
- name of the jobbuildNumber
- job build numberartifactName
- - name of the artifact to fetch - can be regexpDiggerClientException
- - when problem with fetching artifacts from jenkinspublic void saveArtifact(String jobName, int buildNumber, String artifactName, File outputFile) throws DiggerClientException
jobName
- name of the jobbuildNumber
- job build numberartifactName
- name of the artifact to fetch - can be regexp for example *.apkoutputFile
- file (location) used to save artifactDiggerClientException
- when problem with fetching artifacts from jenkinspublic String getBuildLogs(String jobName, int buildNumber) throws DiggerClientException
jobName
- name of the jobbuildNumber
- job build numberDiggerClientException
- when problem with fetching artifacts from jenkinspublic List<com.offbytwo.jenkins.model.BuildWithDetails> getBuildHistory(String jobName) throws DiggerClientException
JobWithDetails.getBuilds()
it will return max 100 most-recent builds.
Please note that this approach will take some time since we first fetch the builds in 1 call, then fetch build details in 1 call per build.
jobName
- name of the jobDiggerClientException
- if connection problems occurpublic void streamLogs(String jobName, int buildNumber, LogStreamingOptions options) throws DiggerClientException
jobName
- the job namebuildNumber
- the build numberoptions
- See LogStreamingOptions
DiggerClientException
public void deleteJob(String jobName, String credentialId) throws DiggerClientException
jobName
- the name of the job to delete.credentialId
- the id of the credential to delete. It should be the same id value if gitRepoCredential is provided in #createJob(String, String, String, Credential, List) and it has an id value. Otherwise pass null.DiggerClientException
public com.offbytwo.jenkins.model.BuildWithDetails getBuildDetails(String jobName, int buildNumber) throws DiggerClientException
jobName
- the name of the jobbuildNumber
- the build numberDiggerClientException
public com.offbytwo.jenkins.model.BuildWithDetails cancelBuild(String jobName, int buildNumber) throws DiggerClientException
jobName
- the name of the jobbuildNumber
- the build numberDiggerClientException
public com.offbytwo.jenkins.JenkinsServer getJenkinsServer()
Copyright © 2017 JBoss by Red Hat. All Rights Reserved.