use of hudson.model.TopLevelItem in project configuration-as-code-plugin by jenkinsci.
the class GithubOrganisationFolderTest method configure_github_organisation_folder_seed_job.
// @Test
// Fails as Items do override submit() with manual data-binding implementation
@ConfiguredWithCode("GithubOrganisationFolderTest.yml")
public void configure_github_organisation_folder_seed_job() throws Exception {
final TopLevelItem job = Jenkins.getInstance().getItem("ndeloof");
assertNotNull(job);
assertTrue(job instanceof OrganizationFolder);
OrganizationFolder folder = (OrganizationFolder) job;
assertEquals(1, folder.getNavigators().size());
final GitHubSCMNavigator github = folder.getNavigators().get(GitHubSCMNavigator.class);
assertNotNull(github);
assertEquals("ndeloof", github.getRepoOwner());
}
use of hudson.model.TopLevelItem in project promoted-builds-plugin by jenkinsci.
the class PromotionsDslContextExtensionTest method testShouldGenerateTheCopyArtifactsJob.
@Test
public void testShouldGenerateTheCopyArtifactsJob() throws Exception {
// Given
String dsl = FileUtils.readFileToString(new File("src/test/resources/copyartifacts-example-dsl.groovy"));
FreeStyleProject seedJob = j.createFreeStyleProject();
seedJob.getBuildersList().add(createScript(dsl));
// When
QueueTaskFuture<FreeStyleBuild> scheduleBuild2 = seedJob.scheduleBuild2(0);
// Then (unstable b/c we aren't including the CopyArtifacts dependency)
j.assertBuildStatus(Result.UNSTABLE, scheduleBuild2.get());
TopLevelItem item = j.jenkins.getItem("copy-artifacts-test");
File config = new File(item.getRootDir(), "promotions/Development/config.xml");
String content = Files.toString(config, Charset.forName("UTF-8"));
assert content.contains("<selector class=\"hudson.plugins.copyartifact.SpecificBuildSelector\">");
}
use of hudson.model.TopLevelItem in project promoted-builds-plugin by jenkinsci.
the class ItemPathResolver method getByPath.
/**
* Gets an {@link Item} of the specified type by absolute or relative path.
* <p>
* The implementation retains the original behavior in {@link PromotedBuildParameterDefinition},
* but this method also provides a support of multi-level addressing including special markups
* for the relative addressing.
* </p>
* Effectively, the resolution order is following:
* <ul>
* <li><b>Optional</b> Legacy behavior, which can be enabled by {@link #ENABLE_LEGACY_RESOLUTION_AGAINST_ROOT}.
* If an item for the name exists on the top Jenkins level, it will be returned</li>
* <li>If the path starts with "/", a global addressing will be used</li>
* <li>If the path starts with "./" or "../", a relative addressing will be used</li>
* <li>If there is no prefix, a relative addressing will be tried. If it
* fails, the method falls back to a global one</li>
* </ul>
* For the relative and absolute addressing the engine supports "." and
* ".." markers within the path.
* The first one points to the current element, the second one - to the upper element.
* If the search cannot get a new top element (e.g. reached the root), the method returns {@code null}.
*
* @param <T> Type of the {@link Item} to be retrieved
* @param path Path string to the item.
* @param baseItem Base {@link Item} for the relative addressing. If null,
* this addressing approach will be skipped
* @param type Type of the {@link Item} to be retrieved
* @return Found {@link Item}. Null if it has not been found by all addressing modes
* or the type differs.
*/
@CheckForNull
@SuppressWarnings("unchecked")
@Restricted(NoExternalUse.class)
public static <T extends Item> T getByPath(@Nonnull String path, @CheckForNull Item baseItem, @Nonnull Class<T> type) {
final Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
return null;
}
// Legacy behavior
if (isEnableLegacyResolutionAgainstRoot()) {
TopLevelItem topLevelItem = jenkins.getItem(path);
if (topLevelItem != null && type.isAssignableFrom(topLevelItem.getClass())) {
return (T) topLevelItem;
}
}
// Explicit global addressing
if (path.startsWith("/")) {
return findPath(jenkins, path.substring(1), type);
}
// Try the relative addressing if possible
if (baseItem != null) {
final ItemGroup<?> relativeRoot = baseItem instanceof ItemGroup<?> ? (ItemGroup<?>) baseItem : baseItem.getParent();
final T item = findPath(relativeRoot, path, type);
if (item != null) {
return item;
}
}
// Fallback to the default behavior (addressing from the Jenkins root)
return findPath(jenkins, path, type);
}
use of hudson.model.TopLevelItem in project hudson-2.x by hudson.
the class UpdateJobCommand method run.
protected int run() throws Exception {
Hudson h = Hudson.getInstance();
TopLevelItem item = h.getItem(name);
if (item == null && !create) {
stderr.println("Job '" + name + "' does not exist and create is set to false");
return -1;
}
if (item == null) {
h.checkPermission(Item.CREATE);
h.createProjectFromXML(name, stdin);
} else {
try {
h.checkPermission(Job.CONFIGURE);
File rootDirOfJob = new File(new File(h.getRootDir(), "jobs"), name);
// place it as config.xml
File configXml = Items.getConfigFile(rootDirOfJob).getFile();
IOUtils.copy(stdin, configXml);
item = h.reloadProjectFromDisk(configXml.getParentFile());
} catch (IOException e) {
throw e;
}
}
return 0;
}
use of hudson.model.TopLevelItem in project hudson-2.x by hudson.
the class TopLevelItemOptionHandler method parseArguments.
@Override
public int parseArguments(Parameters params) throws CmdLineException {
Hudson h = Hudson.getInstance();
String src = params.getParameter(0);
TopLevelItem s = h.getItem(src);
if (s == null)
throw new CmdLineException(owner, "No such job '" + src + "' perhaps you meant " + AbstractProject.findNearest(src) + "?");
setter.addValue(s);
return 1;
}
Aggregations