com.dabsquared.gitlabjenkins.connection.GitLabConnection Java Examples

The following examples show how to use com.dabsquared.gitlabjenkins.connection.GitLabConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabConfigurationTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("gitlab/README.md")
public void configure_gitlab_connection() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    final GitLabConnectionConfig gitLabConnections = jenkins.getDescriptorByType(GitLabConnectionConfig.class);
    assertEquals(1, gitLabConnections.getConnections().size());
    final GitLabConnection gitLabConnection = gitLabConnections.getConnections().get(0);
    assertEquals("gitlab_token", gitLabConnection.getApiTokenId());
    assertEquals("my_gitlab_server", gitLabConnection.getName());
    assertEquals("autodetect", gitLabConnection.getClientBuilderId());
    assertEquals("https://gitlab.com/", gitLabConnection.getUrl());
    assertEquals(20, gitLabConnection.getConnectionTimeout());
    assertEquals(10, gitLabConnection.getReadTimeout());
    assertTrue(gitLabConnection.isIgnoreCertificateErrors());
}
 
Example #2
Source File: SettingsUtils.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
static List<String> gitLabConnectionNames() {
    GitLabConnectionConfig config = connectionConfig();
    List<String> names = new ArrayList<>();

    for (GitLabConnection conn : config.getConnections()) {
        names.add(conn.getName());
    }

    return names;
}
 
Example #3
Source File: GitLabHelper.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static GitLabConnection gitLabConnection(String connectionName) {
    for (GitLabConnection conn : connectionConfig().getConnections()) {
        if (conn.getName().equals(connectionName)) {
            return conn;
        }
    }

    throw new NoSuchElementException("unknown gitlab-connection: " + connectionName);
}
 
Example #4
Source File: TestUtility.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
static void setupGitLabConnections(JenkinsRule jenkins, MockServerRule mockServer) throws IOException {
    GitLabConnectionConfig connectionConfig = jenkins.get(GitLabConnectionConfig.class);
    String apiTokenId = "apiTokenId";
    for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
        if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
            List<Domain> domains = credentialsStore.getDomains();
            credentialsStore.addCredentials(domains.get(0),
                new StringCredentialsImpl(CredentialsScope.SYSTEM, apiTokenId, "GitLab API Token", Secret.fromString(TestUtility.API_TOKEN)));
        }
    }
    connectionConfig.addConnection(new GitLabConnection(TestUtility.GITLAB_CONNECTION_V3, "http://localhost:" + mockServer.getPort() + "/gitlab", apiTokenId, new V3GitLabClientBuilder(), false, 10, 10));
    connectionConfig.addConnection(new GitLabConnection(TestUtility.GITLAB_CONNECTION_V4, "http://localhost:" + mockServer.getPort() + "/gitlab", apiTokenId, new V4GitLabClientBuilder(), false, 10, 10));

}
 
Example #5
Source File: GitLabRule.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public GitLabConnectionProperty createGitLabConnectionProperty() throws IOException {
    for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
        if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
            List<Domain> domains = credentialsStore.getDomains();
            credentialsStore.addCredentials(domains.get(0),
                new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "GitLab API Token", Secret.fromString(getApiToken())));
        }
    }

    GitLabConnectionConfig config = Jenkins.getInstance().getDescriptorByType(GitLabConnectionConfig.class);
    GitLabConnection connection = new GitLabConnection("test", url, API_TOKEN_ID, new V3GitLabClientBuilder(), true,10, 10);
    config.addConnection(connection);
    config.save();
    return new GitLabConnectionProperty(connection.getName());
}
 
Example #6
Source File: GitLabHelper.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
private static GitLabAPI gitLabAPI(GitLabConnection connection) throws GitLabAPIException {
    return GitLabAPI.connect(connection.getUrl(), gitLabApiToken(connection.getApiTokenId()), connection.isIgnoreCertificateErrors(), connection.getReadTimeout());
}