Search in sources :

Example 6 with Job

use of hudson.model.Job in project hudson-2.x by hudson.

the class CopyJobCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Item.CREATE);
    if (h.getItem(dst) != null) {
        stderr.println("Job '" + dst + "' already exists");
        return -1;
    }
    h.copy(src, dst);
    Job newJob = (Job) Hudson.getInstance().getItem(dst);
    if (forceSave && null != newJob) {
        newJob.save();
    }
    return 0;
}
Also used : Hudson(hudson.model.Hudson) Job(hudson.model.Job)

Example 7 with Job

use of hudson.model.Job in project blueocean-plugin by jenkinsci.

the class BranchContainerImpl method iterator.

@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator() {
    List<BluePipeline> branches = new ArrayList<>();
    Collection<Job> jobs = pipeline.mbp.getAllJobs();
    jobs = ContainerFilter.filter(jobs);
    for (Job j : jobs) {
        branches.add(new BranchImpl(j, getLink()));
    }
    return Ordering.from(BRANCH_COMPARITOR).sortedCopy(branches).iterator();
}
Also used : ArrayList(java.util.ArrayList) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Job(hudson.model.Job)

Example 8 with Job

use of hudson.model.Job in project blueocean-plugin by jenkinsci.

the class MultiBranchPipelineImpl method favorite.

@Override
public BlueFavorite favorite(@JsonBody BlueFavoriteAction favoriteAction) {
    if (favoriteAction == null) {
        throw new ServiceException.BadRequestExpception("Must provide pipeline name");
    }
    Job job = PrimaryBranch.resolve(mbp);
    if (job == null) {
        throw new ServiceException.BadRequestExpception("no default branch to favorite");
    }
    FavoriteUtil.toggle(favoriteAction, job);
    return new FavoriteImpl(new BranchImpl(job, getLink().rel("branches")), getLink().rel("favorite"));
}
Also used : FavoriteImpl(io.jenkins.blueocean.service.embedded.rest.FavoriteImpl) Job(hudson.model.Job)

Example 9 with Job

use of hudson.model.Job in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testBranchInfo.

@Test
public void testBranchInfo() {
    Job job = mock(Job.class);
    BranchImpl branch = new BranchImpl(job, new Link("foo"));
    assertNotNull(branch.getBranch());
    assertNull(branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    ObjectMetadataAction oma = new ObjectMetadataAction("My Branch", "A feature branch", "https://path/to/branch");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma);
    assertEquals("https://path/to/branch", branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(new PrimaryInstanceMetadataAction());
    assertTrue(branch.getBranch().isPrimary());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 10 with Job

use of hudson.model.Job in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testGetURL.

@Test
public void testGetURL() {
    Job job = mock(Job.class);
    BranchImpl branch = new BranchImpl(job, new Link("foo"));
    assertNotNull(branch.getBranch());
    assertNull(branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    ObjectMetadataAction oma = new ObjectMetadataAction("My Branch", "A feature branch", "https://path/to/branch");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma);
    assertEquals("https://path/to/branch", branch.getBranch().getUrl());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Aggregations

Job (hudson.model.Job)31 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 Hudson (hudson.model.Hudson)7 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)6 FreeStyleProject (hudson.model.FreeStyleProject)5 Run (hudson.model.Run)5 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)5 User (hudson.model.User)4 ICascadingJob (org.hudsonci.api.model.ICascadingJob)4 Item (hudson.model.Item)2 Link (io.jenkins.blueocean.rest.hal.Link)2 IOException (java.io.IOException)2 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 AbstractProject (hudson.model.AbstractProject)1 Descriptor (hudson.model.Descriptor)1 ItemGroup (hudson.model.ItemGroup)1 ParameterDefinition (hudson.model.ParameterDefinition)1