Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CiBuild): extend Jenkins / Docker / Github clients with REST calls #929

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Wither;

@ToString
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Wither
public class GenericArtifact {
public GenericArtifact(String fileName, String displayPath, String relativePath) {
this.fileName = fileName;
Expand All @@ -41,6 +43,7 @@ public GenericArtifact(String type, String name, String version, String referenc
this.name = name;
this.version = version;
this.reference = reference;
this.fileName = String.format("%s:%s", name, version);
}

private String fileName;
Expand All @@ -50,6 +53,7 @@ public GenericArtifact(String type, String name, String version, String referenc
private String name;
private String type;
private String version;
private String url;
private Map<String, String> metadata;
private boolean decorated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Wither;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@Wither
public class GenericBuild {
private boolean building;
private String fullDisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class JenkinsConfig {
host.name,
jenkinsClient(
host,
jenkinsOkHttpClientProvider.provide(host),
jenkinsRetrofitRequestInterceptorProvider.provide(host),
jenkinsOkHttpClientProvider,
jenkinsRetrofitRequestInterceptorProvider,
registry,
retrofitLogLevel,
igorConfigurationProperties.client.timeout
Expand Down Expand Up @@ -128,13 +128,15 @@ class JenkinsConfig {
.registerModule(new JaxbAnnotationModule())
}

static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host,
OkHttpClient client,
RequestInterceptor requestInterceptor,
Registry registry,
RestAdapter.LogLevel retrofitLogLevel,
int timeout = 30000) {
static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host,
JenkinsOkHttpClientProvider jenkinsOkHttpClientProvider = null,
JenkinsRetrofitRequestInterceptorProvider jenkinsRetrofitRequestInterceptorProvider = null,
Registry registry = null,
RestAdapter.LogLevel retrofitLogLevel = RestAdapter.LogLevel.BASIC,
int timeout = 30000){

OkHttpClient client = (jenkinsOkHttpClientProvider != null) ? jenkinsOkHttpClientProvider.provide(host) : new OkHttpClient()
nimakaviani marked this conversation as resolved.
Show resolved Hide resolved
RequestInterceptor requestInterceptor = (jenkinsRetrofitRequestInterceptorProvider != null) ? jenkinsRetrofitRequestInterceptorProvider.provide(host): RequestInterceptor.NONE
OkHttpClient.Builder clientBuilder = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS)

if (host.skipHostnameVerification) {
Expand Down Expand Up @@ -195,6 +197,7 @@ class JenkinsConfig {
.build()
.create(JenkinsClient)
}

private static TrustManager[] createTrustStore(String trustStoreName,
String trustStorePassword,
String trustStoreType) {
Expand All @@ -208,11 +211,6 @@ class JenkinsConfig {
return trustManagerFactory.trustManagers
}

static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host, Registry registry = null, RestAdapter.LogLevel retrofitLogLevel = RestAdapter.LogLevel.BASIC, int timeout = 30000) {
OkHttpClient client = new OkHttpClient()
jenkinsClient(host, client, RequestInterceptor.NONE, registry, retrofitLogLevel, timeout)
}

static class TrustAllTrustManager implements X509TrustManager {
@Override
void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class JenkinsProperties implements BuildServerProperties<JenkinsProperties.Jenki

Boolean skipHostnameVerification = false

Boolean ciEnabled = false

Permissions.Builder permissions = new Permissions.Builder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ class TaggedImage {
String commitId
String date
String branch
Map<String, Object> artifact
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ interface JenkinsClient {
@GET('/job/{jobName}/lastCompletedBuild/api/xml')
Build getLatestBuild(@EncodedPath('jobName') String jobName)

@GET('/job/{jobName}/lastCompletedBuild/consoleText')
Response getLatestBuildOutput(@EncodedPath('jobName') String jobName)

@GET('/job/{jobName}/{buildNumber}/consoleText')
Response getBuildOutput(@EncodedPath('jobName') String jobName, @Path('buildNumber') String buildNumber)

@GET('/queue/item/{itemNumber}/api/xml')
QueuedJob getQueuedItem(@Path('itemNumber') Integer item)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Build {
List<TestResults> testResults

GenericBuild genericBuild(String jobName) {
GenericBuild genericBuild = new GenericBuild(building: building, number: number.intValue(), duration: duration.intValue(), result: result as Result, name: jobName, url: url, timestamp: timestamp, fullDisplayName: fullDisplayName)
GenericBuild genericBuild = new GenericBuild(id: "${jobName}-${String.valueOf(number)}", building: building, number: number.intValue(), duration: duration.intValue(), result: result as Result, name: jobName, url: url, timestamp: timestamp, fullDisplayName: fullDisplayName)
if (artifacts) {
genericBuild.artifacts = artifacts.collect { buildArtifact ->
GenericArtifact artifact = buildArtifact.getGenericArtifact()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.igor.scm.github.client

import com.netflix.spinnaker.igor.scm.github.client.model.Commit
import com.netflix.spinnaker.igor.scm.github.client.model.CompareCommitsResponse
import com.netflix.spinnaker.igor.scm.github.client.model.GetRepositoryContentResponse
import retrofit.http.GET
Expand Down Expand Up @@ -48,5 +49,12 @@ interface GitHubClient {
@Path(value = 'path', encode = false) String path,
@Query('ref') String ref
)

@GET('/repos/{projectKey}/{repositorySlug}/git/commits/{sha}')
Commit commitInfo(
@Path('projectKey') String projectKey,
@Path('repositorySlug') String repositorySlug,
@Path('sha') String sha
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.spinnaker.igor.scm.github.client


import com.netflix.spinnaker.igor.scm.AbstractScmMaster
import com.netflix.spinnaker.igor.scm.github.client.model.Commit
import com.netflix.spinnaker.igor.scm.github.client.model.GetRepositoryContentResponse
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
Expand Down Expand Up @@ -75,4 +76,8 @@ class GitHubMaster extends AbstractScmMaster {
}
}

@Override
Commit getCommitDetails(String projectKey, String repositorySlug, String sha) {
return gitHubClient.commitInfo(projectKey, repositorySlug, sha)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ class Commit {
String sha
@JsonProperty(value = "commit")
CommitInfo commitInfo
String message
String html_url
Author author
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ public String getTextFileContents(
public String getTextFileContents(String projectKey, String repositorySlug, String path) {
return getTextFileContents(projectKey, repositorySlug, path, ScmMaster.DEFAULT_GIT_REF);
}

public Object getCommitDetails(String projectKey, String repositorySlug, String commitSha) {
nimakaviani marked this conversation as resolved.
Show resolved Hide resolved
throw new UnsupportedOperationException("Not implemented");
}
}