Search in sources :

Example 1 with Error

use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.

the class GitPipelineCreateRequest method validate.

@Override
protected List<Error> validate(String name, BlueScmConfig scmConfig) {
    List<Error> errors = new ArrayList<>();
    if (scmConfig.getUri() == null) {
        errors.add(new ErrorMessage.Error("scmConfig.uri", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "uri is required"));
    } else {
        StandardCredentials credentials = null;
        String credentialId = computeCredentialId(scmConfig);
        if (credentialId != null) {
            credentials = GitUtils.getCredentials(Jenkins.get(), scmConfig.getUri(), credentialId);
            if (credentials == null) {
                errors.add(new ErrorMessage.Error("scmConfig.credentialId", ErrorMessage.Error.ErrorCodes.NOT_FOUND.toString(), String.format("credentialId: %s not found", credentialId)));
            }
        }
        // validate credentials if no credential id (perhaps git repo doesn't need auth or credentials is present)
        if (credentialId == null || credentials != null) {
            errors.addAll(GitUtils.validateCredentials(scmConfig.getUri(), credentials));
        }
    }
    return errors;
}
Also used : Error(io.jenkins.blueocean.commons.ErrorMessage.Error) ArrayList(java.util.ArrayList) Error(io.jenkins.blueocean.commons.ErrorMessage.Error) ErrorMessage(io.jenkins.blueocean.commons.ErrorMessage) StandardCredentials(com.cloudbees.plugins.credentials.common.StandardCredentials)

Example 2 with Error

use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.

the class AbstractMultiBranchCreateRequest method validateInternal.

private void validateInternal(String name, BlueScmConfig scmConfig, BlueOrganization organization) {
    checkUserIsAuthenticatedAndHasItemCreatePermission(organization);
    // If scmConfig is empty then we are missing the uri and name
    if (scmConfig == null) {
        throw fail(new Error("scmConfig", ErrorCodes.MISSING.toString(), "scmConfig is required"));
    }
    if (scmConfig.getUri() == null) {
        throw fail(new Error(ERROR_FIELD_SCM_CONFIG_URI, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_URI + " is required"));
    }
    if (getName() == null) {
        throw fail(new Error(ERROR_FIELD_SCM_CONFIG_NAME, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_NAME + " is required"));
    }
    List<Error> errors = new ArrayList<>(new LinkedList(validate(name, scmConfig)));
    // Validate that name matches rules
    try {
        Jenkins.get().getProjectNamingStrategy().checkName(getName());
        Jenkins.checkGoodName(name);
    } catch (Failure f) {
        errors.add(new Error(ERROR_FIELD_SCM_CONFIG_NAME, Error.ErrorCodes.INVALID.toString(), getName() + " in not a valid name"));
    }
    ModifiableTopLevelItemGroup parent = getParent(organization);
    if (parent.getItem(name) != null) {
        errors.add(new Error(ERROR_NAME, Error.ErrorCodes.ALREADY_EXISTS.toString(), getName() + " already exists"));
    }
    if (!errors.isEmpty()) {
        throw fail(errors);
    }
}
Also used : ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) ArrayList(java.util.ArrayList) Error(io.jenkins.blueocean.commons.ErrorMessage.Error) LinkedList(java.util.LinkedList) Failure(hudson.model.Failure)

Example 3 with Error

use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.

the class AbstractMultiBranchCreateRequest method assignCredentialToProject.

private void assignCredentialToProject(BlueScmConfig scmConfig, MultiBranchProject project) throws IOException {
    User authenticatedUser = User.current();
    String credentialId = computeCredentialId(scmConfig);
    if (StringUtils.isNotBlank(credentialId)) {
        Domain domain = CredentialsUtils.findDomain(credentialId, authenticatedUser);
        if (domain == null) {
            throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to create pipeline").add(new Error(ERROR_FIELD_SCM_CREDENTIAL_ID, Error.ErrorCodes.INVALID.toString(), "No domain in user credentials found for credentialId: " + credentialId)));
        }
        if (StringUtils.isEmpty(scmConfig.getUri())) {
            throw new ServiceException.BadRequestException("uri not specified");
        }
        if (domain.test(new BlueOceanDomainRequirement())) {
            // this is blueocean specific domain
            project.addProperty(new BlueOceanCredentialsProvider.FolderPropertyImpl(authenticatedUser.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(scmConfig.getUri())));
        }
    }
}
Also used : User(hudson.model.User) BlueOceanCredentialsProvider(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider) BlueOceanDomainRequirement(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement) Error(io.jenkins.blueocean.commons.ErrorMessage.Error) Domain(com.cloudbees.plugins.credentials.domains.Domain) ErrorMessage(io.jenkins.blueocean.commons.ErrorMessage)

Aggregations

Error (io.jenkins.blueocean.commons.ErrorMessage.Error)3 ErrorMessage (io.jenkins.blueocean.commons.ErrorMessage)2 ArrayList (java.util.ArrayList)2 StandardCredentials (com.cloudbees.plugins.credentials.common.StandardCredentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 Failure (hudson.model.Failure)1 User (hudson.model.User)1 BlueOceanCredentialsProvider (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider)1 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)1 LinkedList (java.util.LinkedList)1 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)1