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());
}
}
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);
}
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);
}
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() + "'");
}
Aggregations