use of io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequest method create.
@Override
public BluePipeline create(Reachable parent) throws IOException {
User authenticatedUser = User.current();
if (authenticatedUser == null) {
throw new ServiceException.UnauthorizedException("Must login to create a pipeline");
}
String sourceUri = scmConfig.getUri();
if (sourceUri == null) {
throw new ServiceException.BadRequestExpception(new ErrorMessage(400, "Failed to create Git pipeline:" + getName()).add(new ErrorMessage.Error("scmConfig.uri", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "uri is required")));
}
TopLevelItem item = create(Jenkins.getInstance(), getName(), MODE, MultiBranchProjectDescriptor.class);
if (item instanceof WorkflowMultiBranchProject) {
WorkflowMultiBranchProject project = (WorkflowMultiBranchProject) item;
if (StringUtils.isNotBlank(scmConfig.getCredentialId())) {
Domain domain = CredentialsUtils.findDomain(scmConfig.getCredentialId(), authenticatedUser);
if (domain == null) {
throw new ServiceException.BadRequestExpception(new ErrorMessage(400, "Failed to create pipeline").add(new ErrorMessage.Error("scm.credentialId", ErrorMessage.Error.ErrorCodes.INVALID.toString(), "No domain in user credentials found for credentialId: " + scmConfig.getCredentialId())));
}
if (domain.test(new BlueOceanDomainRequirement())) {
//this is blueocean specific domain
project.addProperty(new BlueOceanCredentialsProvider.FolderPropertyImpl(authenticatedUser.getId(), scmConfig.getCredentialId(), BlueOceanCredentialsProvider.createDomain(sourceUri)));
}
}
String credentialId = StringUtils.defaultString(scmConfig.getCredentialId());
project.getSourcesList().add(new BranchSource(new GitSCMSource(null, sourceUri, credentialId, "*", "", false)));
project.scheduleBuild(new Cause.UserIdCause());
return new MultiBranchPipelineImpl(project);
} else {
try {
// we don't know about this project type
item.delete();
} catch (InterruptedException e) {
throw new ServiceException.UnexpectedErrorException("Failed to delete pipeline: " + getName());
}
}
return null;
}
Aggregations