jetbrains.buildServer.serverSide.SRunningBuild Java Examples

The following examples show how to use jetbrains.buildServer.serverSide.SRunningBuild. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BranchesAndPullRequestsParametersPreprocessorTest.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> executeProcessor(Map<String, String> buildParams, boolean featureEnabled, String teamCityVersion) {
    final Map<String, String> runParameters = new HashMap<>();

    final SRunningBuild build = mock(SRunningBuild.class);
    when(build.getBuildLog()).thenReturn(mock(BuildLog.class));
    if (featureEnabled) {
        final SBuildFeatureDescriptor mockbf = mock(SBuildFeatureDescriptor.class);
        when(mockbf.getType()).thenReturn(BranchesAndPullRequestsBuildFeature.BUILD_FEATURE_TYPE);

        when(build.getBuildFeaturesOfType(BranchesAndPullRequestsBuildFeature.BUILD_FEATURE_TYPE)).thenReturn(Collections.singleton(mockbf));
    }

    BranchesAndPullRequestsParametersPreprocessor processor = spy(BranchesAndPullRequestsParametersPreprocessor.class);
    when(processor.getServerVersionInfo()).thenReturn(mockServerVersionInfo(teamCityVersion));
    processor.fixRunBuildParameters(build, runParameters, buildParams);
    return buildParams;
}
 
Example #2
Source File: PayloadContentCommits.java    From tcSlackBuildNotifier with MIT License 6 votes vote down vote up
public void populateCommits(SRunningBuild sRunningBuild) {
    List<SVcsModification> changes = sRunningBuild.getContainingChanges();
    if (changes == null) {
        return;
    }

    for (SVcsModification change : changes) {
        Collection<SUser> committers = change.getCommitters();
        String slackUserId = null;
        if (!committers.isEmpty()) {
            SUser committer = committers.iterator().next();
            slackUserId = committer.getPropertyValue(SlackNotificator.USERID_KEY);
            Loggers.ACTIVITIES.debug("Resolved committer " + change.getUserName() + " to Slack User " + slackUserId);
        }
        commits.add(new Commit(change.getVersion(), change.getDescription(), change.getUserName(), slackUserId));
    }
}
 
Example #3
Source File: ReportsFeature.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
public ReportsFeature(EventDispatcher<BuildServerListener> dispatcher, @NotNull ReportsDescriptor descriptor, @NotNull ReportsConstants constants) {
    this.editParametersUrl = descriptor.getFeaturePath();
    this.constants = constants;
    this.jsonFactory = JacksonFactory.getDefaultInstance();

    try {
        this.httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    } catch (GeneralSecurityException | IOException e) {
        throw new RuntimeException(e);
    }

    if (dispatcher != null) {
        dispatcher.addListener(new BuildServerAdapter() {
            @Override
            public void buildFinished(SRunningBuild build) {
                handleBuildFinished(build);
            }
        });
    }
}
 
Example #4
Source File: ReportsFeature.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
protected void handleBuildFinished(SRunningBuild build) {
    final SBuildType bt = build.getBuildType();
    if (bt == null) {
        return;
    }

    for (SBuildFeatureDescriptor feature : bt.getBuildFeatures()) {
        if (getType().equalsIgnoreCase(feature.getType())) {
            handleBuildFinished(build, feature);
            break;
        }
    }
}
 
Example #5
Source File: ReportsMain.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ReportsDescriptor descriptor = new ReportsDescriptorMock();
    ReportsConstants constants = new ReportsConstants();
    ReportsFeature feature = new ReportsFeature(null, descriptor, constants);
    SRunningBuild build = new SRunningBuildMock();
    SBuildFeatureDescriptor fd = new SBuildFeatureDescriptorMock();

    feature.handleTokens(PARAMS);
    feature.handleBuildFinished(build, fd);
}
 
Example #6
Source File: BuildTracker.java    From TeamCity-Phabricator-Plugin with MIT License 4 votes vote down vote up
public BuildTracker(SRunningBuild build){
    this.build = build;
    this.appConfig = new AppConfig();
    this.tests = new HashMap<>();
    Loggers.SERVER.info("Tracking build" + build.getBuildNumber());
}
 
Example #7
Source File: BranchesAndPullRequestsParametersPreprocessor.java    From TeamCity.SonarQubePlugin with Apache License 2.0 4 votes vote down vote up
@Override
public void fixRunBuildParameters(SRunningBuild build, Map<String, String> runParameters, Map<String, String> buildParams) {

    if (build.getBuildFeaturesOfType(BranchesAndPullRequestsBuildFeature.BUILD_FEATURE_TYPE).isEmpty() || buildParams.containsKey(SQS_SYSENV)) {
        // Currently only GitHub is supported => if feature defined, it is for GitHub
        // ParametersPreprocessor is called for each steps (or could be defined manually). So if sysenv already defined, skip process.
        return;
    }

    if (!isTeamCityMinimalVersion(getServerVersionInfo())) {
        build.getBuildLog().message(
                String.format("Build feature '%s' requiers TeamCity 2019.2 or above", BranchesAndPullRequestsBuildFeature.BUILD_FEATURE_NAME),
                Status.ERROR, MessageAttrs.attrs());
        return;
    }

    String branchIsDefault = buildParams.get("teamcity.build.branch.is_default");
    if (StringUtils.isEmpty(branchIsDefault) || Boolean.TRUE.equals(Boolean.valueOf(branchIsDefault))) {
        // No information or default branch, nothing to provide
        return;
    }

    final String type;
    final JsonObject json = new JsonObject();
    final String prNumber = buildParams.get("teamcity.pullRequest.number");
    if (StringUtils.isEmpty(prNumber)) {
        // Branch
        type = "branch";
        final String vcsBranch = buildParams.get("vcsroot.branch");
        json.addProperty("sonar.branch.name", buildParams.get("teamcity.build.branch"));
        json.addProperty("sonar.branch.target", vcsBranch.substring(vcsBranch.indexOf("refs/heads/") + 11));
    } else {
        // Pull Request
        type = "pull-request";
        String repo = buildParams.get("vcsroot.url");
        repo = repo.replaceFirst("^git@.*:", "");
        repo = repo.replaceFirst("^https?://[^/]*/", "");
        repo = repo.replaceFirst("\\.git$", "");

        json.addProperty("sonar.pullrequest.key", prNumber);
        json.addProperty("sonar.pullrequest.branch", buildParams.get("teamcity.pullRequest.title"));
        json.addProperty("sonar.pullrequest.base", buildParams.get("teamcity.pullRequest.target.branch"));
        json.addProperty("sonar.pullrequest.provider", "github");
        json.addProperty("sonar.pullrequest.github.repository", repo);
    }

    final String jsonString = json.toString();
    build.getBuildLog().message(String.format("SonarQube plugin detects %s, '%s' set with '%s'", type, SQS_SYSENV, jsonString), Status.NORMAL,
            MessageAttrs.attrs());
    buildParams.put(SQS_SYSENV, jsonString);
}
 
Example #8
Source File: SlackNotificationMockingFramework.java    From tcSlackBuildNotifier with MIT License votes vote down vote up
public SRunningBuild getRunningBuild();