Missing feature branch commit hash during TC build queued phase (buildTypeAddedToQueue listener).

Hi,

Writing to inquire about the problem I have. Here is what I've got:

I need to develop a TC plugin that will keep track of build info and publish events (with such data) to further internal applications. I am using "buildTypeAddedToQueue" TC server listener. During this (queued build) TC event required info is the changes of the current branch for this build that was queued (last commit hash to be exact).

This configuration bellow works just fine when using VCSRoot default branch (build has single VCSRoot configured):

List<VcsRootInstanceEntry> vcsRootEntries = queuedBuild.getBuildPromotion().getVcsRootEntries();
if (vcsRootEntries.size() > 0) {
VcsRootInstance vcsRootInstance = vcsRootEntries.get(0).getVcsRoot();
try {
RepositoryVersion current = vcsRootInstance.getCurrentRevision();
Loggers.SERVER.info(String.format("%s Current VCS entry branch: %s", PRE_LOG, current.getVcsBranch()));
commitHash = current.getVersion();
Loggers.SERVER.info(String.format("%s Current VCS entry version: %s", PRE_LOG, commitHash));
} catch (VcsException e) {
Loggers.SERVER.error(String.format("%s VCS error: %s", PRE_LOG, e.getMessage()));
}
}


However, for builds with other branches - "vcsRootInstance.getCurrentRevision().getVersion()" still points to default branch changes. I've also tried to retrieve this information using "build.vcs.number" parameter:

ParametersProvider provider = queuedBuild.getBuildPromotion().getBuildType().getParametersProvider();
Loggers.SERVER.info(String.format("%-40s%s%n", k, provider.get("build.vcs.number")));

This results with "???" value during build queued TC event phase and it only gets resolved to a correct commit hash on build finished event. Business logic requires me to have events aligned, so using build finished listener is not an option for me. 

Is there something I am missing here or how else can I resolve this issue? Any help is appreciated. 

Thanks

Linas

4 comments
Comment actions Permalink

Hi,

build changes are calculated while the build is waiting in the queue, so you should use the 'changesLoaded' event instead of 'buildTypeAddedToQueue'

0
Comment actions Permalink

Thanks for quick response Dmitry. Just tested this and it doesn't seem to work. 'changesLoaded' event's SRunningBuild bean contains ParametersProvider with build.vcs.number = "???" - not loaded yet.

@Override
public void changesLoaded(@NotNull SRunningBuild build) {
ParametersProvider provider = build.getBuildPromotion().getBuildType().getParametersProvider();
Loggers.SERVER.info(String.format("%-40s%s%n", "build.vcs.number", provider.get("build.vcs.number")));
}
[2020-08-21 15:36:32,804]   INFO -   jetbrains.buildServer.SERVER - build.vcs.number                        ???


Also perhaps there is somewhere extensive documentation pages that cover possible examples and explanations of how to use plethora of functions available in particular use cases? 

Thanks again!

Linas

0
Comment actions Permalink

Hi, do you need to get SHA of the latest commit used in the build? If yes, then you should do something like this:

build.getRevisions().get(0).getRevision()
0
Comment actions Permalink

Yes, that is what I was looking for. Thanks!

0

Please sign in to leave a comment.