本文整理了Java中jenkins.model.Jenkins.getItemByFullName()
方法的一些代码示例,展示了Jenkins.getItemByFullName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getItemByFullName()
方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getItemByFullName
[英]Gets the Item object by its full name. Full names are like path names, where each name of Item is combined by '/'.
[中]按项目对象的全名获取该项目对象。全名类似于路径名,其中项目的每个名称由“/”组合而成。
代码示例来源:origin: jenkinsci/jenkins
public @CheckForNull Item getItemByFullName(String fullName) {
return getItemByFullName(fullName,Item.class);
}
代码示例来源:origin: jenkinsci/jenkins
private Object readResolve() {
Jenkins j = Jenkins.getInstanceOrNull();
if (j == null) {
return null;
}
// Will generally only work if called after job loading:
return j.getItemByFullName(fullName);
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public Object fromString(String string) {
Object item = Jenkins.getInstance().getItemByFullName(string);
if(item==null) throw new NoSuchElementException("No such job exists: "+string);
return item;
}
代码示例来源:origin: jenkinsci/jenkins
public Job getProject() {
return Jenkins.getInstance().getItemByFullName(projectName, Job.class);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public Object fromString(String string) {
String[] split = string.split("#");
String projectName = split[0];
int buildNumber = Integer.parseInt(split[1]);
Job<?,?> job = (Job<?,?>) Jenkins.getInstance().getItemByFullName(projectName);
if(job==null) throw new NoSuchElementException("No such job exists: "+projectName);
Run<?,?> run = job.getBuildByNumber(buildNumber);
if(run==null) throw new NoSuchElementException("No such build: "+string);
return run;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @since 1.505
*/
public @CheckForNull Run<?,?> getUpstreamRun() {
Job<?,?> job = Jenkins.getInstance().getItemByFullName(upstreamProject, Job.class);
return job != null ? job.getBuildByNumber(upstreamBuild) : null;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void onLoad(@Nonnull Job<?,?> _job, int _buildNumber) {
Item i = Jenkins.getInstance().getItemByFullName(this.upstreamProject);
if (i == null || !(i instanceof Job)) {
// cannot initialize upstream causes
return;
}
Job j = (Job)i;
for (Cause c : this.upstreamCauses) {
c.onLoad(j, upstreamBuild);
}
}
代码示例来源:origin: jenkinsci/jenkins
protected int run() throws Exception {
Jenkins jenkins = Jenkins.getActiveInstance();
if (jenkins.getItemByFullName(dst)!=null) {
throw new IllegalStateException("Job '"+dst+"' already exists");
}
ModifiableTopLevelItemGroup ig = jenkins;
int i = dst.lastIndexOf('/');
if (i > 0) {
String group = dst.substring(0, i);
Item item = jenkins.getItemByFullName(group);
if (item == null) {
throw new IllegalArgumentException("Unknown ItemGroup " + group);
}
if (item instanceof ModifiableTopLevelItemGroup) {
ig = (ModifiableTopLevelItemGroup) item;
} else {
throw new IllegalStateException("Can't create job from CLI in " + group);
}
dst = dst.substring(i + 1);
}
ig.copy(src,dst).save();
return 0;
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets the {@link Job} that this pointer points to,
* or null if such a job no longer exists.
*/
@WithBridgeMethods(value=AbstractProject.class, castRequired=true)
public Job<?,?> getJob() {
return Jenkins.getInstance().getItemByFullName(name, Job.class);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns true if {@link BuildPtr} points to the given job
* or one of its subordinates.
*
* <p>
* This is useful to check if an artifact in MavenModule
* belongs to MavenModuleSet.
*/
public boolean belongsTo(Job job) {
Item p = Jenkins.getInstance().getItemByFullName(name);
while(p!=null) {
if(p==job)
return true;
// go up the chain while we
ItemGroup<? extends Item> parent = p.getParent();
if (!(parent instanceof Item)) {
return false;
}
p = (Item) parent;
}
return false;
}
代码示例来源:origin: jenkinsci/jenkins
public ParameterValue createValue(String value) {
return new JobParameterValue(getName(), Jenkins.getInstance().getItemByFullName(value,Job.class));
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns true if any of the builds recorded in this fingerprint
* is still retained.
*
* <p>
* This is used to find out old fingerprint records that can be removed
* without losing too much information.
*/
public synchronized boolean isAlive() {
if(original!=null && original.isAlive())
return true;
for (Entry<String,RangeSet> e : usages.entrySet()) {
Job j = Jenkins.getInstance().getItemByFullName(e.getKey(),Job.class);
if(j==null)
continue;
Run firstBuild = j.getFirstBuild();
if(firstBuild==null)
continue;
int oldest = firstBuild.getNumber();
if(!e.getValue().isSmallerThan(oldest))
return true;
}
return false;
}
代码示例来源:origin: jenkinsci/jenkins
@Override public int parseArguments(Parameters params) throws CmdLineException {
final Jenkins j = Jenkins.get();
final String src = params.getParameter(0);
T s = j.getItemByFullName(src, type());
if (s == null) {
final Authentication who = Jenkins.getAuthentication();
try (ACLContext acl = ACL.as(ACL.SYSTEM)) {
Item actual = j.getItemByFullName(src);
if (actual == null) {
LOGGER.log(Level.FINE, "really no item exists named {0}", src);
} else {
LOGGER.log(Level.WARNING, "running as {0} could not find {1} of {2}", new Object[] {who.getPrincipal(), actual, type()});
}
}
T nearest = Items.findNearest(type(), src, j);
if (nearest != null) {
throw new IllegalArgumentException("No such job '" + src + "'; perhaps you meant '" + nearest.getFullName() + "'?");
} else {
throw new IllegalArgumentException("No such job '" + src + "'");
}
}
setter.addValue(s);
return 1;
}
代码示例来源:origin: jenkinsci/jenkins
private void locationChanged(Item item, String oldName, String newName) {
if (item instanceof Job) {
Job p = Jenkins.getInstance().getItemByFullName(newName, Job.class);
if (p != null) {
RunList<? extends Run> builds = p.getBuilds();
for (Run build : builds) {
Collection<Fingerprint> fingerprints = build.getBuildFingerprints();
for (Fingerprint f : fingerprints) {
try {
f.rename(oldName, newName);
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to update fingerprint record " + f.getFileName() + " when " + oldName + " was renamed to " + newName, e);
}
}
}
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
private @CheckForNull TopLevelItem resolveName(String name) {
TopLevelItem item = getOwner().getItemGroup().getItem(name);
if (item == null) {
name = Items.getCanonicalName(getOwner().getItemGroup(), name);
item = Jenkins.getInstance().getItemByFullName(name, TopLevelItem.class);
}
return item;
}
代码示例来源:origin: jenkinsci/jenkins
private static SaveableReference referTo(Saveable s) {
if (s instanceof Run) {
Job parent = ((Run) s).getParent();
if (Jenkins.getInstance().getItemByFullName(parent.getFullName()) == parent) {
return new RunSaveableReference((Run) s);
}
}
return new SimpleSaveableReference(s);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
List<Action> actions) {
AbstractProject downstream = getDownstreamProject();
if (Jenkins.getInstance().getItemByFullName(downstream.getFullName()) != downstream) { // this checks Item.READ also on parent folders
LOGGER.log(Level.WARNING, "Running as {0} cannot even see {1} for trigger from {2}", new Object[] {Jenkins.getAuthentication().getName(), downstream, getUpstreamProject()});
return false; // do not even issue a warning to build log
}
if (!downstream.hasPermission(Item.BUILD)) {
listener.getLogger().println(Messages.BuildTrigger_you_have_no_permission_to_build_(ModelHyperlinkNote.encodeTo(downstream)));
return false;
}
return build.getResult().isBetterOrEqualTo(threshold);
}
});
代码示例来源:origin: jenkinsci/jenkins
/**
* Used for CLI binding.
*/
@CLIResolver
public static AbstractProject resolveForCLI(
@Argument(required=true,metaVar="NAME",usage="Job name") String name) throws CmdLineException {
AbstractProject item = Jenkins.getInstance().getItemByFullName(name, AbstractProject.class);
if (item==null) {
AbstractProject project = AbstractProject.findNearest(name);
throw new CmdLineException(null, project == null ? Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name)
: Messages.AbstractItem_NoSuchJobExists(name, project.getFullName()));
}
return item;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Used for CLI binding.
*/
@CLIResolver
public static AbstractItem resolveForCLI(
@Argument(required=true,metaVar="NAME",usage="Item name") String name) throws CmdLineException {
// TODO can this (and its pseudo-override in AbstractProject) share code with GenericItemOptionHandler, used for explicit CLICommand’s rather than CLIMethod’s?
AbstractItem item = Jenkins.getInstance().getItemByFullName(name, AbstractItem.class);
if (item==null) {
AbstractItem project = Items.findNearest(AbstractItem.class, name, Jenkins.getInstance());
throw new CmdLineException(null, project == null ? Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name)
: Messages.AbstractItem_NoSuchJobExists(name, project.getFullName()));
}
return item;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Used for CLI binding.
*/
@Restricted(DoNotUse.class)
@SuppressWarnings("rawtypes")
@CLIResolver
static ParameterizedJob resolveForCLI(@Argument(required=true, metaVar="NAME", usage="Job name") String name) throws CmdLineException {
ParameterizedJob item = Jenkins.getInstance().getItemByFullName(name, ParameterizedJob.class);
if (item == null) {
ParameterizedJob project = Items.findNearest(ParameterizedJob.class, name, Jenkins.getInstance());
throw new CmdLineException(null, project == null ?
hudson.model.Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name) :
hudson.model.Messages.AbstractItem_NoSuchJobExists(name, project.getFullName()));
}
return item;
}
内容来源于网络,如有侵权,请联系作者删除!