Search in sources :

Example 16 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringWithCustomRequirements.

@Test
public void testBuildTriggeringWithCustomRequirements() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addRequirement(new Requirement("id1", "propName", "value", RequirementType.EQUALS));
    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().getRequirements().size());
    }
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        PropEntitiesAgentRequirement agentRequirements = new PropEntitiesAgentRequirement();
        PropEntityAgentRequirement agentRequirement = new PropEntityAgentRequirement();
        agentRequirement.type = RequirementType.EQUALS.getName();
        agentRequirement.properties = new Properties(createMap("property-name", "propName2", "property-value", "value2"), null, Fields.ALL, getBeanContext(myFixture));
        agentRequirements.propEntities = Arrays.asList(agentRequirement);
        buildTypeEntity.setAgentRequirements(agentRequirements);
        build.setBuildType(buildTypeEntity);
        // this line can be removed after TW-44714 fix
        build.setProperties(new Properties(createMap("disableBuildMerging", "See TW-44714"), null, Fields.ALL, getBeanContext(myFixture)));
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        List<Requirement> actualAgentRequirements = ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getRequirements();
        assertEquals(1, actualAgentRequirements.size());
        assertEquals("propName2", actualAgentRequirements.iterator().next().getPropertyName());
    }
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) 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 17 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method getRequirementSetting.

@GET
@Path("/{btLocator}/agent-requirements/{agentRequirementLocator}/{fieldName}")
@Produces({ "text/plain" })
@ApiOperation(value = "Get a setting of an agent requirement of the matching build configuration.", nickname = "getAgentRequirementParameter")
public String getRequirementSetting(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("agentRequirementLocator") String agentRequirementLocator, @PathParam("fieldName") String name) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement requirement = getAgentRequirement(buildType, agentRequirementLocator);
    String id = requirement.getId();
    if (id == null) {
        throw new BadRequestException("Could not get field of a requirement which does not have id");
    }
    return PropEntityStep.getSetting(buildType.get(), id, name);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method getAgentRequirement.

@GET
@Path("/{btLocator}/agent-requirements/{agentRequirementLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get an agent requirement of the matching build configuration.", nickname = "getAgentRequirement")
public PropEntityAgentRequirement getAgentRequirement(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("agentRequirementLocator") String agentRequirementLocator, @QueryParam("fields") String fields) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final Requirement requirement = getAgentRequirement(buildType, agentRequirementLocator);
    return new PropEntityAgentRequirement(requirement, buildType.getSettingsEx(), new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Requirement(jetbrains.buildServer.requirements.Requirement) ApiOperation(io.swagger.annotations.ApiOperation)

Example 19 with Requirement

use of jetbrains.buildServer.requirements.Requirement in project teamcity-rest by JetBrains.

the class BuildTypeRequest method getAgentRequirement.

public static Requirement getAgentRequirement(@NotNull final BuildTypeOrTemplate buildType, @Nullable final String agentRequirementLocator) {
    if (StringUtil.isEmpty(agentRequirementLocator)) {
        throw new BadRequestException("Empty agent requirement locator is not supported.");
    }
    final Locator locator = new Locator(agentRequirementLocator);
    final String requirementId;
    if (locator.isSingleValue()) {
        requirementId = locator.getSingleValue();
    } else {
        requirementId = locator.getSingleDimensionValue("id");
    }
    locator.checkLocatorFullyProcessed();
    if (StringUtil.isEmpty(requirementId)) {
        throw new BadRequestException("Cannot find id in agent requirement locator '" + agentRequirementLocator + "'");
    }
    for (Requirement requirement : buildType.get().getRequirements()) {
        String id = requirement.getId();
        if (requirementId.equals(id != null ? id : requirement.getPropertyName())) {
            return requirement;
        }
    }
    // may be it is a property name: use obsolete pre-TeamCity 10 logic
    for (Requirement requirement : buildType.get().getRequirements()) {
        if (requirementId.equals(requirement.getPropertyName())) {
            LOG.debug("Found agent requirement by parameter name '" + requirementId + "' instead of id." + (requirement.getId() != null ? " This behavior is obsolete, use id (" + requirement.getId() + ") instead of parameter name." : ""));
            return requirement;
        }
    }
    throw new NotFoundException("Could not find agent requirement by id '" + requirementId + "' in " + buildType.getText() + " with id '" + buildType.getId() + "'");
}
Also used : Requirement(jetbrains.buildServer.requirements.Requirement) ServiceLocator(jetbrains.buildServer.ServiceLocator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Aggregations

Requirement (jetbrains.buildServer.requirements.Requirement)19 Test (org.testng.annotations.Test)10 ApiOperation (io.swagger.annotations.ApiOperation)6 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 TestFor (jetbrains.buildServer.util.TestFor)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 NotNull (org.jetbrains.annotations.NotNull)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 RequirementFactory (jetbrains.buildServer.serverSide.RequirementFactory)1 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)1 SUser (jetbrains.buildServer.users.SUser)1