Search in sources :

Example 1 with Pipeline

use of org.gitlab4j.api.models.Pipeline in project legend-sdlc by finos.

the class GitLabApiWithFileAccess method waitForPipelinesDeleteBranchAndVerify.

protected static boolean waitForPipelinesDeleteBranchAndVerify(GitLabApi gitLabApi, GitLabProjectId projectId, String branchName) {
    LOGGER.debug("Checking for pending pipelines for branch {} in project {}", branchName, projectId);
    try {
        Pager<Pipeline> pendingPipelines = GitLabApiTools.callWithRetries(() -> gitLabApi.getPipelineApi().getPipelines(projectId.getGitLabId(), Constants.PipelineScope.PENDING, PipelineStatus.PENDING, branchName, false, null, null, null, null, 1), 10, 1000L);
        if (!PagerTools.isEmpty(pendingPipelines)) {
            LOGGER.debug("Found pending pipelines for branch {} in project {}", branchName, projectId);
            return false;
        }
    } catch (Exception e) {
        if (GitLabApiTools.isRetryableGitLabApiException(e)) {
            return false;
        }
        // Don't let a non-retryable exception here block the delete
        LOGGER.warn("Error checking for pending pipelines for branch {} in project {}", branchName, projectId, e);
    }
    LOGGER.debug("Found no pending pipelines for branch {} in project {}", branchName, projectId);
    LOGGER.debug("Checking for running pipelines for branch {} in project {}", branchName, projectId);
    try {
        Pager<Pipeline> runningPipelines = GitLabApiTools.callWithRetries(() -> gitLabApi.getPipelineApi().getPipelines(projectId.getGitLabId(), Constants.PipelineScope.RUNNING, PipelineStatus.RUNNING, branchName, false, null, null, null, null, 1), 10, 1000L);
        if (!PagerTools.isEmpty(runningPipelines)) {
            LOGGER.debug("Found running pipelines for branch {} in project {}", branchName, projectId);
            return false;
        }
    } catch (Exception e) {
        if (GitLabApiTools.isRetryableGitLabApiException(e)) {
            return false;
        }
        // Don't let a non-retryable exception here block the delete
        LOGGER.warn("Error checking for running pipelines for branch {} in project {}", branchName, projectId, e);
    }
    LOGGER.debug("Found no running pipelines for branch {} in project {}", branchName, projectId);
    LOGGER.debug("Deleting branch {} in project {}", branchName, projectId);
    try {
        boolean success = GitLabApiTools.deleteBranchAndVerify(gitLabApi, projectId.getGitLabId(), branchName, 5, 1000L);
        if (success) {
            LOGGER.debug("Deleted branch {} in project {}", branchName, projectId);
        } else {
            LOGGER.debug("Did not delete branch {} in project {}", branchName, projectId);
        }
        return success;
    } catch (Exception e) {
        // a "not found" exception means the branch isn't there, and so doesn't need to be deleted
        if (GitLabApiTools.isNotFoundGitLabApiException(e)) {
            LOGGER.debug("Branch {} in project {} cannot be found: no need to delete", branchName, projectId);
            return true;
        }
        StringBuilder builder = new StringBuilder("Error deleting branch ").append(branchName).append(" in project ").append(projectId);
        StringTools.appendThrowableMessageIfPresent(builder, e);
        String message = builder.toString();
        LOGGER.error(message, e);
        throw new LegendSDLCServerException(message, e);
    }
}
Also used : LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Pipeline(org.gitlab4j.api.models.Pipeline)

Example 2 with Pipeline

use of org.gitlab4j.api.models.Pipeline in project choerodon-starters by open-hand.

the class PipelineApi method cancelPipelineJobs.

/**
 * Cancel jobs of specified pipelines in a project.
 * <p>
 * POST /projects/:id/pipelines/:pipeline_id/cancel
 *
 * @param projectId  the project ID to cancel jobs for speficied pipeline
 * @param pipelineId the pipeline ID to cancel jobs
 * @return pipeline instance which just canceled
 * @throws GitLabApiException if any exception occurs during execution
 */
public Pipeline cancelPipelineJobs(int projectId, int pipelineId) throws GitLabApiException {
    GitLabApiForm formData = null;
    Response response = post(Response.Status.OK, formData, "projects", projectId, "pipelines", pipelineId, "cancel");
    return (response.readEntity(Pipeline.class));
}
Also used : Response(javax.ws.rs.core.Response) Pipeline(org.gitlab4j.api.models.Pipeline)

Example 3 with Pipeline

use of org.gitlab4j.api.models.Pipeline in project choerodon-starters by open-hand.

the class PipelineApi method createPipeline.

/**
 * Create a pipelines in a project.
 *
 * <pre><code>GitLab Endpoint: POST /projects/:id/pipeline</code></pre>
 *
 * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
 * @param ref reference to commit
 * @param variables a Map containing the variables available in the pipeline
 * @return a Pipeline instance with the newly created pipeline info
 * @throws GitLabApiException if any exception occurs during execution
 */
public Pipeline createPipeline(Object projectIdOrPath, String ref, List<Variable> variables) throws GitLabApiException {
    if (ref == null || ref.trim().isEmpty()) {
        throw new GitLabApiException("ref cannot be null or empty");
    }
    if (variables == null || variables.isEmpty()) {
        GitLabApiForm formData = new GitLabApiForm().withParam("ref", ref, true);
        Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline");
        return (response.readEntity(Pipeline.class));
    }
    // class is used to create the JSON for the POST data.
    class CreatePipelineForm {

        @SuppressWarnings("unused")
        public String ref;

        @SuppressWarnings("unused")
        public List<Variable> variables;

        CreatePipelineForm(String ref, List<Variable> variables) {
            this.ref = ref;
            this.variables = variables;
        }
    }
    CreatePipelineForm pipelineForm = new CreatePipelineForm(ref, variables);
    Response response = post(Response.Status.CREATED, pipelineForm, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline");
    return (response.readEntity(Pipeline.class));
}
Also used : Response(javax.ws.rs.core.Response) List(java.util.List) Pipeline(org.gitlab4j.api.models.Pipeline)

Example 4 with Pipeline

use of org.gitlab4j.api.models.Pipeline in project choerodon-starters by open-hand.

the class PipelineApi method retryPipelineJob.

/**
 * Retry a job in specified pipelines in a project.
 * <p>
 * POST /projects/:id/pipelines/:pipeline_id/retry
 *
 * @param projectId  the project ID to retry a job for speficied pipeline
 * @param pipelineId the pipeline ID to retry a job from
 * @return pipeline instance which just retried
 * @throws GitLabApiException if any exception occurs during execution
 */
public Pipeline retryPipelineJob(int projectId, int pipelineId) throws GitLabApiException {
    GitLabApiForm formData = null;
    Response response = post(Response.Status.CREATED, formData, "projects", projectId, "pipelines", pipelineId, "retry");
    return (response.readEntity(Pipeline.class));
}
Also used : Response(javax.ws.rs.core.Response) Pipeline(org.gitlab4j.api.models.Pipeline)

Example 5 with Pipeline

use of org.gitlab4j.api.models.Pipeline in project choerodon-starters by open-hand.

the class PipelineApi method getPipelines.

/**
 * Get a list of pipelines in a project in the specified page range.
 * <p>
 * GET /projects/:id/pipelines
 *
 * @param projectId  the project ID to get the list of pipelines for
 * @param scope      the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
 * @param status     the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
 * @param ref        the ref of pipelines
 * @param yamlErrors returns pipelines with invalid configurations
 * @param name       the name of the user who triggered pipelines
 * @param username   the username of the user who triggered pipelines
 * @param orderBy    order pipelines by ID, STATUS, REF, USER_ID (default: ID)
 * @param sort       sort pipelines in ASC or DESC order (default: DESC)
 * @param page       the page to get
 * @param perPage    the number of Pipeline instances per page
 * @return a list containing the pipelines for the specified project ID
 * @throws GitLabApiException if any exception occurs during execution
 */
public List<Pipeline> getPipelines(int projectId, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors, String name, String username, PipelineOrderBy orderBy, SortOrder sort, int page, int perPage) throws GitLabApiException {
    GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope).withParam("status", status).withParam("ref", ref).withParam("yaml_errors", yamlErrors).withParam("name", name).withParam("username", username).withParam("order_by", orderBy).withParam("sort", sort).withParam("page", page).withParam(PER_PAGE_PARAM, perPage);
    Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines");
    return (response.readEntity(new GenericType<List<Pipeline>>() {
    }));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Pipeline(org.gitlab4j.api.models.Pipeline)

Aggregations

Pipeline (org.gitlab4j.api.models.Pipeline)7 Response (javax.ws.rs.core.Response)5 GitLabApiException (org.gitlab4j.api.GitLabApiException)2 CIPluginServices (com.hp.octane.integrations.CIPluginServices)1 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)1 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 CIProxyConfiguration (com.hp.octane.integrations.dto.configuration.CIProxyConfiguration)1 CIBuildStatusInfo (com.hp.octane.integrations.dto.general.CIBuildStatusInfo)1 CIJobsList (com.hp.octane.integrations.dto.general.CIJobsList)1 CIPluginInfo (com.hp.octane.integrations.dto.general.CIPluginInfo)1 CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)1 CIParameter (com.hp.octane.integrations.dto.parameters.CIParameter)1 CIParameters (com.hp.octane.integrations.dto.parameters.CIParameters)1 PipelineNode (com.hp.octane.integrations.dto.pipelines.PipelineNode)1 CIBuildResult (com.hp.octane.integrations.dto.snapshots.CIBuildResult)1 CIBuildStatus (com.hp.octane.integrations.dto.snapshots.CIBuildStatus)1 com.hp.octane.integrations.dto.tests (com.hp.octane.integrations.dto.tests)1 PermissionException (com.hp.octane.integrations.exceptions.PermissionException)1 EncodeCiJobBase64Parameter (com.hp.octane.integrations.services.configurationparameters.EncodeCiJobBase64Parameter)1 ConfigurationParameterFactory (com.hp.octane.integrations.services.configurationparameters.factory.ConfigurationParameterFactory)1