下面列出了hudson.model.Item#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@NonNull
@Override
public VaultConfiguration forJob(@NonNull Item job) {
VaultConfiguration resultingConfig = null;
for (ItemGroup g = job.getParent(); g instanceof AbstractFolder;
g = ((AbstractFolder) g).getParent()) {
FolderVaultConfiguration folderProperty = ((AbstractFolder<?>) g).getProperties()
.get(FolderVaultConfiguration.class);
if (folderProperty == null) {
continue;
}
if (resultingConfig != null) {
resultingConfig = resultingConfig
.mergeWithParent(folderProperty.getConfiguration());
} else {
resultingConfig = folderProperty.getConfiguration();
}
}
return resultingConfig;
}
@Restricted(NoExternalUse.class)
private String getApiToken(String apiTokenId, Item item) {
ItemGroup<?> context = null != item ? item.getParent() : Jenkins.get();
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
lookupCredentials(
StandardCredentials.class,
context,
ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()),
CredentialsMatchers.withId(apiTokenId));
if (credentials != null) {
if (credentials instanceof GitLabApiToken) {
return ((GitLabApiToken) credentials).getApiToken().getPlainText();
}
if (credentials instanceof StringCredentials) {
return ((StringCredentials) credentials).getSecret().getPlainText();
}
}
throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId);
}
@Override
public BluePipeline getPipeline(Item item, Reachable parent, BlueOrganization organization) {
if (item instanceof WorkflowJob && item.getParent() instanceof MultiBranchProject) {
return new BranchImpl(organization, (Job) item, parent.getLink());
}
return null;
}
@Override
public Resource resolve(Item context, Reachable parent, Item target, BlueOrganization organization) {
if (context==target.getParent()) {
return getPipeline(context, parent, organization);
}
return null;
}
@Override
public Resource resolve(Item context, Reachable parent, Item target, BlueOrganization organization) {
if (context instanceof MultiBranchProject) {
if (context == target)
return getPipeline(context, parent, organization);
if (context == target.getParent()) {
// target is a branch
return getPipeline(context, parent, organization).getBranches().get(target.getName());
}
}
return null;
}
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public void onDeleted(Item item) {
if (!(item instanceof Job)) {
return;
}
ItemGroup<? extends Item> parent = item.getParent();
if (!(parent instanceof MultiBranchProject)) {
return;
}
Job j = (Job) item;
MultiBranchProject mb = (MultiBranchProject) parent;
Branch branch = mb.getProjectFactory().getBranch(j);
SCMHead head = branch.getHead();
Consumer<GitHubRepo> plunger = null;
if (head instanceof GitHubBranchSCMHead) {
plunger = r -> r.getBranchRepository().getBranches().remove(head.getName());
} else if (head instanceof GitHubTagSCMHead) {
plunger = r -> r.getTagRepository().getTags().remove(head.getName());
} else if (head instanceof GitHubPRSCMHead) {
GitHubPRSCMHead prHead = (GitHubPRSCMHead) head;
plunger = r -> r.getPrRepository().getPulls().remove(prHead.getPrNumber());
}
if (plunger != null) {
for (SCMSource src : (List<SCMSource>) mb.getSCMSources()) {
if (src instanceof GitHubSCMSource) {
GitHubSCMSource gsrc = (GitHubSCMSource) src;
plunger.accept(gsrc.getLocalRepo());
LOG.info("Plunging local data for {}", item.getFullName());
}
}
}
}
private StringBuilder retrieveParentUrl(Item item) {
if (item.getParent() instanceof Item) {
Item parent = (Item) item.getParent();
return retrieveParentUrl(parent).append('/').append(Util.rawEncode(parent.getName()));
} else {
return new StringBuilder();
}
}
@Override
public Boolean apply(Item item) {
return item.getParent() instanceof MultiBranchProject;
}
@Override
public Boolean apply(Item item) {
return item.getClass().getName().equals("hudson.matrix.MatrixConfiguration") || item.getParent() instanceof MatrixProject;
}
private void maybeEnrichMessage(@Nonnull Message message) {
String channelName = message.getChannelName();
if (channelName.equals(Events.JobChannel.NAME) && message instanceof JobChannelMessage) {
JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
Item jobChannelItem = jobChannelMessage.getJobChannelItem();
if(jobChannelItem == null){
return;
}
Link jobUrl = LinkResolver.resolveLink(jobChannelItem);
if (jobUrl == null) {
return;
}
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(jobChannelItem);
if (org!=null) {
message.set(EventProps.Jenkins.jenkins_org, org.getName());
}
jobChannelMessage.set(BlueEventProps.blueocean_job_rest_url, jobUrl.getHref());
jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, AbstractPipelineImpl.getFullName(org, jobChannelItem));
if (jobChannelItem instanceof WorkflowJob) {
ItemGroup<? extends Item> parent = jobChannelItem.getParent();
if (parent instanceof WorkflowMultiBranchProject) {
String multiBranchProjectName = AbstractPipelineImpl.getFullName(org, (WorkflowMultiBranchProject)parent);
jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, multiBranchProjectName);
jobChannelMessage.set(BlueEventProps.blueocean_job_branch_name, jobChannelItem.getName());
}
}
if (message.containsKey("job_run_queueId") && jobChannelItem instanceof hudson.model.Job) {
String queueIdStr = message.get("job_run_queueId");
if (queueIdStr == null) {
return;
}
final long queueId = Long.parseLong(queueIdStr);
Queue.Item queueItem = Jenkins.getInstance().getQueue().getItem(queueId);
if (queueItem == null) {
return;
}
hudson.model.Job job = (hudson.model.Job) jobChannelItem;
BlueQueueItem blueQueueItem = QueueUtil.getQueuedItem(null, queueItem, job);
if (blueQueueItem != null) {
jobChannelMessage.set(BlueEventProps.blueocean_queue_item_expected_build_number, Integer.toString(blueQueueItem.getExpectedBuildNumber()));
} else {
// If build is already running, we simply take the run id and pass it on
if(message.get("job_run_status") != null){
String buildNumberStr = message.get("jenkins_object_id");
if(StringUtils.isNotBlank(buildNumberStr)) {
jobChannelMessage.set(BlueEventProps.blueocean_queue_item_expected_build_number, message.get("jenkins_object_id"));
}
}
}
}
}
}