Search in sources :

Example 6 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggering1.

@Test
public void testBuildTriggering1() {
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final SUser triggeringUser = getOrCreateUser("user");
    final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertEquals(myBuildType, queuedBuild.getBuildPromotion().getBuildType());
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 7 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnCloudAgentTriggering.

@Test
public void testBuildOnCloudAgentTriggering() throws NoSuchAgentPoolException, AgentPoolCannotBeRenamedException, PoolQuotaExceededException {
    int cloudAgentTypeId = myFixture.getAgentTypeManager().getOrCreateAgentTypeId(new AgentTypeKey("Cloud", "Profile", "Image"));
    final SUser triggeringUser = getOrCreateUser("user");
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        Agent submittedAgent = new Agent();
        submittedAgent.typeId = cloudAgentTypeId;
        build.setAgent(submittedAgent);
        SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        assertNotNull(queuedBuild.getAgentRestrictor());
        assertEquals(AgentRestrictorType.CLOUD_IMAGE, queuedBuild.getAgentRestrictor().getType());
        assertEquals(cloudAgentTypeId, queuedBuild.getAgentRestrictor().getId());
    }
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
        Agent submittedAgent = new Agent();
        submittedAgent.locator = "id:" + agent2.getId();
        submittedAgent.typeId = cloudAgentTypeId;
        build.setAgent(submittedAgent);
        SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        assertNotNull(queuedBuild.getAgentRestrictor());
        assertEquals(AgentRestrictorType.SINGLE_AGENT, queuedBuild.getAgentRestrictor().getType());
        assertEquals(agent2.getId(), queuedBuild.getAgentRestrictor().getId());
    }
    {
        final Build build = new Build();
        final BuildType buildType = new BuildType();
        buildType.setId(myBuildType.getExternalId());
        build.setBuildType(buildType);
        Agent submittedAgent = new Agent();
        submittedAgent.typeId = cloudAgentTypeId + 10;
        build.setAgent(submittedAgent);
        checkException(NotFoundException.class, () -> build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>()), "triggering build on not existent agent type");
    }
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) SUser(jetbrains.buildServer.users.SUser) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 8 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringWithArtifactDeps.

@Test
public void testBuildTriggeringWithArtifactDeps() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
    BuildTypeImpl buildType3 = registerBuildType("buildType3", "projectName");
    BuildTypeImpl buildType4 = registerBuildType("buildType4", "projectName");
    SFinishedBuild build2_1 = build().in(buildType2).finish();
    SFinishedBuild build2_2 = build().in(buildType2).finish();
    SFinishedBuild build3_1 = build().in(buildType3).finish();
    SFinishedBuild build3_2 = build().in(buildType3).finish();
    SFinishedBuild build4_1 = build().in(buildType4).finish();
    ArtifactDependencyFactory depsFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    SArtifactDependency dep2 = depsFactory.createArtifactDependency(buildType2, "path", RevisionRules.LAST_FINISHED_RULE);
    dep2.setCleanDestinationFolder(true);
    SArtifactDependency dep3 = depsFactory.createArtifactDependency(buildType3, "path2", RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber()));
    dep3.setCleanDestinationFolder(false);
    buildType1.setArtifactDependencies(Arrays.asList(dep2, dep3));
    final SUser user = getOrCreateUser("user");
    // end of setup
    final Build build = new Build();
    final BuildType buildTypeEntity = new BuildType();
    buildTypeEntity.setId(buildType1.getExternalId());
    build.setBuildType(buildTypeEntity);
    SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType2.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals("latest.lastFinished", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(1).getSourceBuildTypeId());
    assertEquals(build3_1.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(1).getRevisionRule().getRevision());
    Builds builds1 = new Builds();
    Build build1 = new Build();
    build1.setLocator("buildType:(id:" + buildType3.getExternalId() + "),number:" + build3_2.getBuildNumber());
    builds1.builds = Arrays.asList(build1);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build3_2.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    Builds builds2 = new Builds();
    Build build2 = new Build();
    build2.setLocator("buildType:(id:" + buildType4.getExternalId() + "),number:" + build4_1.getBuildNumber());
    builds2.builds = Arrays.asList(build2);
    build.setBuildArtifactDependencies(builds2);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with artifact dependency not in default artifact dependencies");
    build.setBuildArtifactDependencies(builds1);
    PropEntitiesArtifactDep propEntitiesArtifactDep1 = new PropEntitiesArtifactDep();
    propEntitiesArtifactDep1.setReplace("false");
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build3_2.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals(buildType2.getId(), result.getBuildPromotion().getArtifactDependencies().get(1).getSourceBuildTypeId());
    assertEquals("latest.lastFinished", result.getBuildPromotion().getArtifactDependencies().get(1).getRevisionRule().getRevision());
    PropEntitiesArtifactDep propEntitiesArtifactDep2 = new PropEntitiesArtifactDep();
    PropEntityArtifactDep propEntityArtifactDep1 = new PropEntityArtifactDep();
    propEntityArtifactDep1.properties = new Properties(createMap("revisionName", "buildId", "revisionValue", "1000", "pathRules", "path3", "cleanDestinationDirectory", "true"), null, Fields.ALL_NESTED, getBeanContext(myFixture));
    propEntityArtifactDep1.sourceBuildType = new BuildType();
    propEntityArtifactDep1.sourceBuildType.setId(buildType4.getExternalId());
    propEntityArtifactDep1.type = "artifact_dependency";
    propEntitiesArtifactDep2.propEntities = Arrays.asList(propEntityArtifactDep1);
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep2);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with artifact dependency not in posted custom-artifact-dependnecies");
    build.setBuildArtifactDependencies(null);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType4.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals("1000" + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals("path3", result.getBuildPromotion().getArtifactDependencies().get(0).getSourcePaths());
    assertEquals(true, result.getBuildPromotion().getArtifactDependencies().get(0).isCleanDestinationFolder());
    build.setBuildArtifactDependencies(builds2);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType4.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build4_1.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    propEntitiesArtifactDep2.setReplace("false");
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep2);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(3, result.getBuildPromotion().getArtifactDependencies().size());
}
Also used : Builds(jetbrains.buildServer.server.rest.model.build.Builds) SUser(jetbrains.buildServer.users.SUser) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 9 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringWithCustomSteps.

@Test
public void testBuildTriggeringWithCustomSteps() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addBuildRunner("stepName", "runner", createMap("a", "b"));
    final SUser user = getOrCreateUser("user");
    // end of setup
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        build.setBuildType(buildTypeEntity);
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        // noinspection ConstantConditions
        assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners().size());
    }
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        PropEntitiesStep steps = new PropEntitiesStep();
        PropEntityStep step = new PropEntityStep();
        step.type = "runner2";
        step.properties = new Properties(createMap("x", "y"), null, Fields.ALL, getBeanContext(myFixture));
        steps.propEntities = Arrays.asList(step);
        buildTypeEntity.setSteps(steps);
        build.setBuildType(buildTypeEntity);
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        // noinspection ConstantConditions
        Collection<? extends SBuildStepDescriptor> actualSteps = ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners();
        assertEquals(1, actualSteps.size());
        assertEquals("runner2", actualSteps.iterator().next().getType());
    }
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        PropEntitiesStep steps = new PropEntitiesStep();
        PropEntityStep step = new PropEntityStep();
        step.type = "runner2";
        step.properties = new Properties(createMap("x", "y"), null, Fields.ALL, getBeanContext(myFixture));
        steps.propEntities = Arrays.asList(step);
        step.disabled = true;
        buildTypeEntity.setSteps(steps);
        build.setBuildType(buildTypeEntity);
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        // noinspection ConstantConditions
        assertEquals(0, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners().size());
    }
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 10 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildPromotionFinderTest method testDefaultsLegacy.

@Test
public void testDefaultsLegacy() {
    // turn on pre-TeamCity 10 mode
    setInternalProperty("rest.buildPromotionFinder.varyingDefaults", "false");
    final SProject project = createProject("prj", "project");
    final BuildTypeEx buildConf1 = (BuildTypeEx) project.createBuildType("buildConf1", "buildConf1");
    SUser user1 = createUser("user1");
    final BuildPromotion build10 = build().in(buildConf1).finish().getBuildPromotion();
    final BuildPromotion build15 = build().in(buildConf1).personalForUser("user1").finish().getBuildPromotion();
    final BuildPromotion build20 = build().in(buildConf1).failedToStart().finish().getBuildPromotion();
    final BuildPromotion build30 = build().in(buildConf1).cancel(user1).getBuildPromotion();
    SFinishedBuild finishedBuild40 = build().in(buildConf1).withBranch("branch1").tag("tag").finish();
    finishedBuild40.setPinned(true, null, null);
    final BuildPromotion build40 = finishedBuild40.getBuildPromotion();
    final BuildPromotion build45 = build().in(buildConf1).withBranch("branch1").personalForUser("user1").finish().getBuildPromotion();
    final BuildPromotion build50 = build().in(buildConf1).withBranch("branch1").failedToStart().by(user1).finish().getBuildPromotion();
    final BuildPromotion build60 = build().in(buildConf1).withBranch("branch1").cancel(user1).getBuildPromotion();
    final BuildPromotion build100 = build().in(buildConf1).run().getBuildPromotion();
    myFixture.createEnabledAgent("agent2", "runner1");
    myFixture.createEnabledAgent("agent3", "runner1");
    final BuildPromotion build110 = build().in(buildConf1).withBranch("branch1").by(user1).run().getBuildPromotion();
    final BuildPromotion build120 = build().in(buildConf1).withBranch("branch1").personalForUser("user1").failedToStart().tag("tag").run().getBuildPromotion();
    final BuildPromotion build130 = build().in(buildConf1).addToQueue().getBuildPromotion();
    final BuildPromotion build140 = build().in(buildConf1).withBranch("branch1").addToQueue().getBuildPromotion();
    final BuildPromotion build150 = build().in(buildConf1).withBranch("branch1").personalForUser("user1").addToQueue().getBuildPromotion();
    check("defaultFilter:false", build130, build140, build150, build120, build110, build100, build60, build50, build45, build40, build30, build20, build15, build10);
    check(null, build10);
    check("state:finished", build10);
    check("state:(finished:true)", build10);
    check("running:false", build10);
    // bug here with state processing    check("state:(finished:false)", build130, build140, build150, build120, build110, build100);
    // bug here with state processing    check("state:(finished:any)", build130, build140, build150, build120, build110, build100, build60, build50, build45, build40, build30, build20, build15, build10);
    check("state:(finished:true,running:true)", build100, build10);
    check("state:(finished:true,queued:true)", build130, build10);
    check("running:true", build100);
    check("state:(running)", build100);
    check("state:(running:true)", build100);
    check("branch:(branch1)", build40);
    check("branch:(branch1),running:true", build110);
    check("agent:(id:" + build100.getAssociatedBuild().getAgent().getId() + ")", build10);
    check("agent:(id:" + build110.getAssociatedBuild().getAgent().getId() + ")");
    check("agent:(id:" + build100.getAssociatedBuild().getAgent().getId() + "),running:any", build100, build10);
    check("agent:(id:" + build100.getAssociatedBuild().getAgent().getId() + "),running:true", build100);
    check("agent:(id:" + build110.getAssociatedBuild().getAgent().getId() + "),running:true");
    check("agent:(id:" + build120.getAssociatedBuild().getAgent().getId() + "),running:true");
    check("agentName:" + build120.getAssociatedBuild().getAgent().getName() + ",running:true");
    check("user:id:" + user1.getId());
    check("user:id:" + user1.getId() + ",state:any");
    check("id:" + build50.getId(), build50);
    check("id:" + build60.getId(), build60);
    check("id:" + build120.getId(), build120);
    check("id:" + build120.getId(), build120);
    check("state:queued", build130);
    check("state:(queued:true,running:true)", build130, build100);
    check("buildType:" + buildConf1.getExternalId(), build10);
    check("buildType:" + buildConf1.getExternalId() + ",running:any", build100, build10);
    // bug here with state processing    check("buildType:" + buildConf1.getExternalId() + ",state:(queued:any)", build130, build100, build10);
    check("buildType:" + buildConf1.getExternalId() + ",state:(queued:true,running:true,finished:true)", build130, build100, build10);
    check("tag:tag");
    check("tag:tag,running:true");
    check("pinned:true");
}
Also used : SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Aggregations

SUser (jetbrains.buildServer.users.SUser)125 Test (org.testng.annotations.Test)70 ApiOperation (io.swagger.annotations.ApiOperation)35 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)35 Build (jetbrains.buildServer.server.rest.model.build.Build)20 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)18 NotNull (org.jetbrains.annotations.NotNull)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)13 Fields (jetbrains.buildServer.server.rest.model.Fields)12 SUserGroup (jetbrains.buildServer.groups.SUserGroup)11 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)10 ServiceLocator (jetbrains.buildServer.ServiceLocator)9 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 Nullable (org.jetbrains.annotations.Nullable)9 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)8 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)7