Search in sources :

Example 6 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class BuildTypeRequest method changeTriggerSetting.

@PUT
@Path("/{btLocator}/triggers/{triggerLocator}/{fieldName}")
@Consumes({ "text/plain" })
@Produces({ "text/plain" })
@ApiOperation(value = "Update a parameter of a trigger of the matching build configuration.", nickname = "setTriggerParameter")
public String changeTriggerSetting(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("triggerLocator") String triggerLocator, @PathParam("fieldName") String name, String newValue) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final BuildTriggerDescriptor trigger = DataProvider.getTrigger(buildType.get(), triggerLocator);
    PropEntityStep.setSetting(buildType.get(), trigger.getId(), name, newValue);
    buildType.persist("Build trigger settings changed");
    return PropEntityStep.getSetting(buildType.get(), DataProvider.getTrigger(buildType.get(), triggerLocator).getId(), name);
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class BuildTypeRequest method addTrigger.

/**
 * Creates new trigger. 'id' attribute is ignored in the submitted descriptor.
 * Reports error if new trigger cannot be created (e.g. only single trigger of the type is allowed for a build configuration).
 */
@POST
@Path("/{btLocator}/triggers")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a trigger to the matching build configuration.", nickname = "addTriggerToBuildType")
public PropEntityTrigger addTrigger(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @QueryParam("fields") String fields, PropEntityTrigger description) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final BuildTriggerDescriptor justAdded = description.addTo(buildType.getSettingsEx(), myServiceLocator);
    buildType.persist("Build trigger added");
    return new PropEntityTrigger(justAdded, buildType.getSettingsEx(), new Fields(fields), myBeanContext);
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class PropEntityTrigger method addToInternalMain.

@NotNull
public BuildTriggerDescriptor addToInternalMain(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
    if (StringUtil.isEmpty(type)) {
        throw new BadRequestException("Build trigger cannot have empty 'type'.");
    }
    BuildTriggerDescriptor similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
    if (inherited != null && inherited && similar != null) {
        return similar;
    }
    if (similar != null && id != null && id.equals(similar.getId())) {
        // todo
        return similar;
    }
    final BuildTriggerDescriptor triggerToAdd = serviceLocator.getSingletonService(BuildTriggerDescriptorFactory.class).createTriggerDescriptor(type, properties == null ? Collections.emptyMap() : properties.getMap(), buildTriggerCustomization == null ? BuildCustomizationSettings.empty() : buildTriggerCustomization.toBuildCustomizationSettings(serviceLocator));
    if (!buildType.addBuildTrigger(triggerToAdd)) {
        String additionalMessage = getDetails(buildType, triggerToAdd);
        throw new OperationException("Build trigger addition failed." + (additionalMessage != null ? " " + additionalMessage : ""));
    }
    if (disabled != null) {
        buildType.setEnabled(triggerToAdd.getId(), !disabled);
    }
    BuildTriggerDescriptor result = buildType.findTriggerById(triggerToAdd.getId());
    if (result == null) {
        throw new OperationException("Cannot find just added trigger with id '" + triggerToAdd.getId() + "'");
    }
    return result;
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildTriggerDescriptorFactory(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptorFactory) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class BuildTypeRequestTest method testCreatingWithTemplate.

@Test
public void testCreatingWithTemplate() {
    // see also alike setup in BuildTypeTest.testInheritance()
    ProjectEx project10 = createProject("project10", "project 10");
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    final SVcsRoot vcsRoot10 = project10.createVcsRoot("vcs", "extId10", "name10");
    final SVcsRoot vcsRoot20 = project10.createVcsRoot("vcs", "extId20", "name20");
    final SVcsRoot vcsRoot30 = project10.createVcsRoot("vcs", "extId30", "name30");
    project10.addParameter(new SimpleParameter("p", "v"));
    BuildTypeEx bt100 = project10.createBuildType("bt100", "bt 100");
    BuildTypeEx bt110 = project10.createBuildType("bt110", "bt 110");
    BuildTypeEx bt120 = project10.createBuildType("bt120", "bt 120");
    // TEMPLATE
    BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "bt 10");
    t10.setArtifactPaths("aaaaa");
    t10.setBuildNumberPattern("pattern");
    t10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, true);
    t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, true);
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_t");
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_AGENT");
    t10.setOption(BuildTypeOptions.BT_FAIL_ON_ANY_ERROR_MESSAGE, true);
    t10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 11);
    t10.addVcsRoot(vcsRoot10);
    t10.addVcsRoot(vcsRoot20);
    t10.setCheckoutRules(vcsRoot20, new CheckoutRules("a=>b"));
    BuildRunnerDescriptorFactory runnerDescriptorFactory = myFixture.getSingletonService(BuildRunnerDescriptorFactory.class);
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run10", "name10", "Ant1", map("a", "b")));
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run20", "name20", "Ant2", map("a", "b")));
    BuildTriggerDescriptor trigger10 = t10.addBuildTrigger("Type", map("a", "b"));
    BuildTriggerDescriptor trigger20 = t10.addBuildTrigger("Type", map("a", "b"));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f10", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f20", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type", map("a", "b")));
    ArtifactDependencyFactory artifactDependencyFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    ArrayList<SArtifactDependency> artifactDeps = new ArrayList<>();
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art10", bt100.getExternalId(), "path1", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art20", bt100.getExternalId(), "path2", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path3", RevisionRules.LAST_PINNED_RULE));
    t10.setArtifactDependencies(artifactDeps);
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt100));
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    t10.addParameter(new SimpleParameter("a10", "b"));
    t10.addParameter(new SimpleParameter("a20", "b"));
    t10.addParameter(new SimpleParameter("a30", "b"));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req10", "a", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req20", "b", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "c", null, RequirementType.EXISTS));
    // BUILD TYPE
    BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
    bt10.attachToTemplate(t10);
    // todo: test w/o override
    bt10.setArtifactPaths("bbbb");
    bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
    bt10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    {
    // hack to reproduce case related to https://youtrack.jetbrains.com/issue/TW-45273
    // comment until TW-45273 is fixed      t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    }
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
    bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
    bt10.addVcsRoot(vcsRoot20);
    bt10.setCheckoutRules(vcsRoot20, new CheckoutRules("x=>y"));
    bt10.addVcsRoot(vcsRoot30);
    bt10.setEnabled("run20", false);
    bt10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run30", "name30", "Ant30", map("a", "b")));
    bt10.setEnabled(trigger20.getId(), false);
    BuildTriggerDescriptor trigger30 = bt10.addBuildTrigger("Type", map("a", "b"));
    bt10.setEnabled("f20", false);
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type_bt", map("a", "b")));
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f40", "type", map("a", "b")));
    ArrayList<SArtifactDependency> artifactDepsBt = new ArrayList<>();
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path30", RevisionRules.LAST_FINISHED_RULE));
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art40", bt100.getExternalId(), "path4", RevisionRules.LAST_PINNED_RULE));
    bt10.setArtifactDependencies(artifactDepsBt);
    bt10.setEnabled("art20", false);
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt120));
    bt10.addParameter(new SimpleParameter("a20", "x"));
    bt10.addParameter(new SimpleParameter("a30", "b"));
    bt10.addParameter(new SimpleParameter("a40", "x"));
    bt10.setEnabled("req20", false);
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "x", null, RequirementType.EQUALS));
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req40", "y", null, RequirementType.EXISTS));
    // NOW, TEST TIME!
    // get buildType
    BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), getBeanContext(myServer));
    // post buildType to create new one
    buildType.initializeSubmittedFromUsual();
    buildType.setId("bt10_copy");
    buildType.setName("bt 10 - copy");
    BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
    // compare initial and new buildType
    BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
    assertNotNull(bt10_copy);
    assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
// todo:
// check different settings in submitted from the inherited one, but with inherited flag
// check submitting with different enabled state
// check submitting with different id
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) ArrayList(java.util.ArrayList) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 10 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class BuildTypeRequest method getTriggerSetting.

@GET
@Path("/{btLocator}/triggers/{triggerLocator}/{fieldName}")
@Produces({ "text/plain" })
@ApiOperation(value = "Get a parameter of a trigger of the matching build configuration.", nickname = "getTriggerParameter")
public String getTriggerSetting(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("triggerLocator") String triggerLocator, @PathParam("fieldName") String name) {
    final BuildTypeSettings buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true).get();
    final BuildTriggerDescriptor trigger = DataProvider.getTrigger(buildType, triggerLocator);
    return PropEntityStep.getSetting(buildType, trigger.getId(), name);
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BuildTriggerDescriptor (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor)11 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)7 ApiOperation (io.swagger.annotations.ApiOperation)6 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)2 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)2 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)2 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)2 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)2 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 BuildTriggerDescriptorFactory (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptorFactory)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)1 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)1 NotNull (org.jetbrains.annotations.NotNull)1