下面列出了hudson.model.Run#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Run getUpstreamBuild(@Nonnull Run build) {
CauseAction causeAction = build.getAction(CauseAction.class);
if (causeAction == null) {
return null;
}
for (Cause cause : causeAction.getCauses()) {
if (cause instanceof Cause.UpstreamCause) {
Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause;
Job upstreamJob =
Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class);
// We want to ignore rebuilds, rebuilds have the same parent as
// original build, see BuildCache#updateCache().
if (upstreamJob == null || build.getParent() == upstreamJob) {
continue;
}
return upstreamJob.getBuildByNumber(upstreamCause.getUpstreamBuild());
}
}
return null;
}
/**
* Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and
* build information.
*
* @param stats Embedded {@link SingleTestFlakyStats} object
* @param build The {@link hudson.model.Run} object to get SCM information from.
*/
public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) {
this.stats = stats;
revision = Integer.toString(build.getNumber());
Job job = build.getParent();
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
if (s != null) {
ArrayList<SCM> scms = new ArrayList<>(s.getSCMs());
SCM scm = scms.size() > 0 ? scms.get(0) : null;
if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) {
GitSCM gitSCM = (GitSCM) scm;
BuildData buildData = gitSCM.getBuildData(build);
if (buildData != null) {
Revision gitRevision = buildData.getLastBuiltRevision();
if (gitRevision != null) {
revision = gitRevision.getSha1String();
}
}
}
}
}
@Override
public String getLabel(@Nullable Run run) {
if (run != null) {
Job job = run.getParent();
ItemGroup parent = job.getParent();
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
if (config != null) {
String label = config.getDockerLabel();
if (!StringUtils.isBlank(label)) {
return label;
}
}
}
if (parent instanceof Item) {
parent = ((Item) parent).getParent();
} else {
parent = null;
}
}
}
return null;
}
@Override
public String getRegistryUrl(@Nullable Run run) {
if (run != null) {
Job job = run.getParent();
ItemGroup parent = job.getParent();
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
if (config != null) {
DockerRegistryEndpoint registry = config.getRegistry();
if (registry != null && !StringUtils.isBlank(registry.getUrl())) {
return registry.getUrl();
}
}
}
if (parent instanceof Item) {
parent = ((Item) parent).getParent();
} else {
parent = null;
}
}
}
return null;
}
@Override
public String getRegistryCredentialsId(@Nullable Run run) {
if (run != null) {
Job job = run.getParent();
ItemGroup parent = job.getParent();
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
if (config != null) {
DockerRegistryEndpoint registry = config.getRegistry();
if (registry != null && !StringUtils.isBlank(registry.getCredentialsId())) {
return registry.getCredentialsId();
}
}
}
if (parent instanceof Item) {
parent = ((Item) parent).getParent();
} else {
parent = null;
}
}
}
return null;
}
/**
* Check if the current Job is permitted to use the cloud.
*
* @param run
* @param kubernetesCloud
* @throws AbortException
* in case the Job has not been authorized to use the
* kubernetesCloud
*/
private void checkAccess(Run<?, ?> run, KubernetesCloud kubernetesCloud) throws AbortException {
Job<?, ?> job = run.getParent(); // Return the associated Job for this Build
ItemGroup<?> parent = job.getParent(); // Get the Parent of the Job (which might be a Folder)
Set<String> allowedClouds = new HashSet<>();
KubernetesFolderProperty.collectAllowedClouds(allowedClouds, parent);
if (!allowedClouds.contains(kubernetesCloud.name)) {
throw new AbortException(String.format("Not authorized to use Kubernetes cloud: %s", step.getCloud()));
}
}
/**
* Handles the rebuild request and redirects to deflake config page
*
* @param request StaplerRequest the request.
* @param response StaplerResponse the response handler.
* @throws java.io.IOException in case of Stapler issues
* @throws javax.servlet.ServletException if something unfortunate happens.
* @throws InterruptedException if something unfortunate happens.
*/
public void doIndex(StaplerRequest request, StaplerResponse response) throws
IOException, ServletException, InterruptedException {
Run currentBuild = request.findAncestorObject(Run.class);
if (currentBuild != null) {
Job job = currentBuild.getParent();
job.checkPermission(AbstractProject.BUILD);
response.sendRedirect(DEFLAKE_CONFIG_URL);
}
}
public static GitLabClient getClient(@NotNull Run<?, ?> build) {
Job<?, ?> job = build.getParent();
if(job != null) {
final GitLabConnectionProperty connectionProperty = job.getProperty(GitLabConnectionProperty.class);
if (connectionProperty != null) {
return connectionProperty.getClient();
}
}
return null;
}
private String getJobName(final Run build) {
final Job parent = build.getParent();
return (parent.getParent() instanceof Job ? (Job) parent.getParent() : parent).getFullDisplayName();
}
public Office365ConnectorWebhookNotifier(Run run, TaskListener taskListener) {
this.run = run;
this.taskListener = taskListener;
this.decisionMaker = new DecisionMaker(run, taskListener);
this.job = run.getParent();
}
public static Job<?, ?> getProject(Run<?, ?> build) {
Object p = build.getParent();
return (Job<?, ?>) p;
}