Search in sources :

Example 1 with GitCredentials

use of com.epam.pipeline.entity.git.GitCredentials in project cloud-pipeline by epam.

the class DtsRunner method runEntry.

private PipelineRun runEntry(DtsRunConfigurationEntry entry, Long configurationId, List<Long> entitiesIds, PipelineConfiguration configuration) {
    Pipeline pipeline = entry.getPipelineId() == null ? null : pipelineManager.load(entry.getPipelineId());
    PipelineRun run = pipelineRunManager.createPipelineRun(entry.getPipelineVersion(), configuration, pipeline, null, entitiesIds, configurationId);
    run.setConfigName(entry.getConfigName());
    run.setDockerImage(toolManager.getExternalToolName(run.getDockerImage()));
    run.setExecutionPreferences(DtsExecutionPreferences.builder().dtsId(entry.getDtsId()).coresNumber(entry.getCoresNumber()).build());
    Map<SystemParams, String> systemParams = pipelineLauncher.matchCommonParams(run, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST_EXTERNAL), configuration.getGitCredentials());
    systemParams.put(SystemParams.DISTRIBUTION_URL, preferenceManager.getPreference(SystemPreferences.DTS_DISTRIBUTION_URL));
    GitCredentials gitCredentials = configuration.getGitCredentials();
    String gitCloneUrl = gitCredentials == null ? run.getRepository() : gitCredentials.getUrl();
    String pipelineCommand = commandBuilder.build(configuration, systemParams);
    run.setActualCmd(pipelineCommand);
    String launchCmd = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_CMD_TEMPLATE);
    String launchScriptUrl = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_URL);
    String fullCmd = String.format(launchCmd, launchScriptUrl, launchScriptUrl, gitCloneUrl, run.getRevisionName(), pipelineCommand);
    pipelineRunManager.save(run);
    DtsSubmission submission = buildSubmission(run, configuration, entry.getCoresNumber(), systemParams, fullCmd);
    log.debug("Creating DTS submission");
    try {
        DtsSubmission scheduled = submissionManager.createSubmission(entry.getDtsId(), submission);
        if (scheduled.getState().getStatus() != TaskStatus.RUNNING) {
            return failRun(run, String.format("Submission failed to start: %s", scheduled.getState().getReason()));
        }
        log.debug("Successfully scheduled submission on DTS");
        return run;
    } catch (DtsRequestException e) {
        return failRun(run, e.getMessage());
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) GitCredentials(com.epam.pipeline.entity.git.GitCredentials) SystemParams(com.epam.pipeline.manager.execution.SystemParams) DtsRequestException(com.epam.pipeline.exception.DtsRequestException) DtsSubmission(com.epam.pipeline.entity.dts.DtsSubmission) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 2 with GitCredentials

use of com.epam.pipeline.entity.git.GitCredentials in project cloud-pipeline by epam.

the class GitManager method checkoutRepo.

private void checkoutRepo(Pipeline pipeline, String version, String repoPath) {
    GitCredentials gitCredentials = getGitCredentials(pipeline.getId(), false);
    final String clone = String.format(GIT_CLONE_CMD, gitCredentials.getUrl(), repoPath);
    cmdExecutor.executeCommand(clone, null, new File(workingDirPath), true);
    final String checkout = String.format(GIT_CHECKOUT_CMD, getRevisionName(version));
    cmdExecutor.executeCommand(checkout, null, new File(repoPath), true);
}
Also used : GitCredentials(com.epam.pipeline.entity.git.GitCredentials) File(java.io.File)

Example 3 with GitCredentials

use of com.epam.pipeline.entity.git.GitCredentials in project cloud-pipeline by epam.

the class GitlabClient method buildCloneCredentials.

public GitCredentials buildCloneCredentials(boolean useEnvVars, boolean issueToken, Long duration) {
    final String gitUrl = StringUtils.isNotBlank(fullUrl) ? fullUrl : gitHost;
    Assert.state(StringUtils.isNotBlank(gitUrl), "Gitlab URL is required to issue credentials.");
    final GitCredentials.GitCredentialsBuilder credentialsBuilder = GitCredentials.builder();
    if (StringUtils.isEmpty(token)) {
        return credentialsBuilder.url(gitUrl).build();
    }
    final String cloneToken;
    final String userName;
    final String email;
    if (issueToken && !externalHost) {
        final GitlabUser user = findUser(this.userName).orElseGet(() -> GitlabUser.builder().username(adminName).id(adminId).build());
        userName = user.getUsername();
        cloneToken = createImpersonationToken(projectName, user.getId(), duration);
        email = user.getEmail();
    } else {
        userName = externalHost ? this.userName.replaceAll("@.*$", "") : adminName;
        cloneToken = token;
        email = null;
    }
    GitRepositoryUrl repositoryUrl = GitRepositoryUrl.from(gitUrl);
    repositoryUrl = useEnvVars ? repositoryUrl.withUsername("${GIT_USER}").withPassword("${GIT_TOKEN}") : repositoryUrl.withUsername(userName).withPassword(cloneToken);
    LOGGER.debug("Ready url for user {} with token {}", userName, cloneToken);
    return credentialsBuilder.url(repositoryUrl.asString()).userName(userName).token(cloneToken).email(email).build();
}
Also used : GitCredentials(com.epam.pipeline.entity.git.GitCredentials) GitRepositoryUrl(com.epam.pipeline.entity.git.GitRepositoryUrl) GitlabUser(com.epam.pipeline.entity.git.GitlabUser)

Example 4 with GitCredentials

use of com.epam.pipeline.entity.git.GitCredentials in project cloud-pipeline by epam.

the class GitlabClientTest method testBuildCloneUrl.

private void testBuildCloneUrl(String user, String url) {
    GitlabClient client = GitlabClient.initializeGitlabClientFromRepositoryAndToken(user, url, TOKEN, null, null, false);
    GitCredentials credentials = client.buildCloneCredentials(true, DURATION);
    Assert.assertNotNull(credentials);
    Assert.assertEquals(USER, credentials.getUserName());
    Assert.assertEquals(TOKEN, credentials.getToken());
    Assert.assertEquals(URL_WITH_ENV_VARS, credentials.getUrl());
}
Also used : GitCredentials(com.epam.pipeline.entity.git.GitCredentials)

Example 5 with GitCredentials

use of com.epam.pipeline.entity.git.GitCredentials in project cloud-pipeline by epam.

the class GitlabClientTest method testBuildCloneCredentialsWithoutToken.

@Test
public void testBuildCloneCredentialsWithoutToken() {
    GitlabClient client = GitlabClient.initializeGitlabClientFromRepositoryAndToken(USER, URL_WITH_USER, "", null, null, false);
    GitCredentials credentials = client.buildCloneCredentials(true, DURATION);
    Assert.assertNotNull(credentials);
    Assert.assertNull(credentials.getUserName());
    Assert.assertNull(credentials.getToken());
    Assert.assertEquals(URL_WITH_USER, credentials.getUrl());
}
Also used : GitCredentials(com.epam.pipeline.entity.git.GitCredentials) Test(org.junit.Test)

Aggregations

GitCredentials (com.epam.pipeline.entity.git.GitCredentials)6 DtsSubmission (com.epam.pipeline.entity.dts.DtsSubmission)1 GitRepositoryUrl (com.epam.pipeline.entity.git.GitRepositoryUrl)1 GitlabUser (com.epam.pipeline.entity.git.GitlabUser)1 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)1 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)1 DtsRequestException (com.epam.pipeline.exception.DtsRequestException)1 SystemParams (com.epam.pipeline.manager.execution.SystemParams)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 File (java.io.File)1 Test (org.junit.Test)1