use of hudson.model.Item in project promoted-builds-plugin by jenkinsci.
the class ItemPathResolverTest method assertsPath.
private <T extends Item> void assertsPath(@Nonnull String path, @CheckForNull Item base, Item expected, @Nonnull Class<T> clazz) throws Exception {
final Item res = ItemPathResolver.getByPath(path, base, clazz);
if (expected != res) {
StringBuilder errorDetails = new StringBuilder("Wrong result for clase='").append(clazz).append("', path='").append(path).append("'");
if (base != null) {
errorDetails.append(" with base element '").append(base.getFullName()).append("'");
} else {
errorDetails.append(" with NULL base element");
}
assertEquals(errorDetails.toString(), expected, res);
}
}
use of hudson.model.Item in project hudson-2.x by hudson.
the class GroovyCommand method run.
protected int run() throws Exception {
// this allows the caller to manipulate the JVM state, so require the admin privilege.
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
Binding binding = new Binding();
binding.setProperty("out", new PrintWriter(stdout, true));
String j = getClientEnvironmentVariable("JOB_NAME");
if (j != null) {
Item job = Hudson.getInstance().getItemByFullName(j);
binding.setProperty("currentJob", job);
String b = getClientEnvironmentVariable("BUILD_NUMBER");
if (b != null && job instanceof AbstractProject) {
Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
binding.setProperty("currentBuild", r);
}
}
GroovyShell groovy = new GroovyShell(binding);
groovy.run(loadScript(), "RemoteClass", remaining.toArray(new String[remaining.size()]));
return 0;
}
use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class GithubPipelineUpdateRequest method update.
@Nonnull
@Override
public BluePipeline update(BluePipeline pipeline) throws IOException {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
User user = User.current();
if (user == null) {
throw new ServiceException.UnauthorizedException("User is not authenticated");
}
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof OrganizationFolder) {
OrganizationFolder folder = (OrganizationFolder) item;
GitHubSCMNavigator gitHubSCMNavigator = getNavigator(folder);
if (gitHubSCMNavigator != null) {
folder.getNavigators().replace(gitHubSCMNavigator);
if (repos.size() == 1) {
SCMSourceEvent.fireNow(new GithubPipelineCreateRequest.SCMSourceEventImpl(repos.get(0), item, gitHubSCMNavigator.getApiUri(), gitHubSCMNavigator));
} else {
folder.scheduleBuild(new Cause.UserIdCause());
}
}
}
return pipeline;
}
use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class PipelineStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
// e.g. /blue/organizations/jenkins/Pipeline (or a url on that)
if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE)) {
// Not interested in it
return null;
}
Jenkins jenkins = Jenkins.getInstance();
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
try {
Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
if (pipelineJobItem != null) {
BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(pipelineJobItem);
if (bluePipeline != null) {
try {
return new FetchData(bluePipeline.getLink().getHref(), ModelObjectSerializer.toJson(bluePipeline));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Serialization error.", pipelineJobItem.getUrl()), e);
return null;
}
} else {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Failed to convert to Blue Ocean Resource.", pipelineJobItem.getUrl()));
return null;
}
}
} catch (Exception e) {
LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName), e);
return null;
}
// Don't preload any data on the page.
return null;
}
use of hudson.model.Item in project blueocean-plugin by jenkinsci.
the class JobIndexingMessageEnricher method enrich.
@Override
public void enrich(@Nonnull Message message) {
if (message instanceof JobChannelMessage) {
JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
Item jobChannelItem = jobChannelMessage.getJobChannelItem();
Enum indexingStatus;
Enum indexingResult;
if (jobChannelItem instanceof OrganizationFolder) {
indexingStatus = JobIndexing.EventProps.job_orgfolder_indexing_status;
indexingResult = JobIndexing.EventProps.job_orgfolder_indexing_result;
} else if (jobChannelItem instanceof MultiBranchProject) {
jobChannelMessage.set(EventProps.Job.job_ismultibranch, "true");
indexingStatus = EventProps.Job.job_multibranch_indexing_status;
indexingResult = EventProps.Job.job_multibranch_indexing_result;
} else {
// don't enrich if not org folder or multibranch
return;
}
if (message instanceof QueueTaskMessage) {
QueueTaskMessage queueTaskMessage = (QueueTaskMessage) message;
Queue.Item queueItem = queueTaskMessage.getQueueItem();
if (queueItem instanceof Queue.LeftItem) {
Queue.LeftItem leftItem = (Queue.LeftItem) queueItem;
if (leftItem.isCancelled()) {
jobChannelMessage.set(indexingStatus, "COMPLETE");
jobChannelMessage.set(indexingResult, "CANCELLED");
} else {
if (message.getEventName().equals(Events.JobChannel.job_run_queue_task_complete.name())) {
jobChannelMessage.set(indexingStatus, "COMPLETE");
Queue.Executable executable = ((Queue.LeftItem) queueItem).getExecutable();
if (executable instanceof BranchIndexing) {
BranchIndexing branchIndexing = (BranchIndexing) executable;
jobChannelMessage.set(indexingResult, branchIndexing.getResult().toString());
} else if (executable instanceof OrganizationFolder.OrganizationScan) {
OrganizationFolder.OrganizationScan orgScan = (OrganizationFolder.OrganizationScan) executable;
jobChannelMessage.set(indexingResult, orgScan.getResult().toString());
}
} else {
jobChannelMessage.set(indexingStatus, "INDEXING");
}
}
} else {
jobChannelMessage.set(indexingStatus, "INDEXING");
}
}
}
}
Aggregations