问题
We are migrating from old XAML
build definition to new TFS 2015 build. In old we have gated-check in that is working fine. In new one we have such option on "Triggers" tab. However I want use commit ID that trigger build.
The variable $(Build.SourceVersion)
is responsible for this, but for gated-check in it is not being set.
It looks right, because commit was not accepted by TFS yet.
The question is how to grab this commit ID either during gated-check in or following CI ?
Should I create just another build for gated check-in that just compile our solution and only if succeeded will trigger CI ?
回答1:
There is no way to get the changeset id that hasn't checked in during gated check-in. Please check the screenshot below, checking in gated changes is in the very last step in the build process, which can't be controlled. After the build completes, the variable $(Build.SourceVersion)
will update automatically. So we are not able to get the changeset id that hasn't checked in until the build completes.
You would need to use TFS REST API to get the build that has completed, then fetch the "sourceVersion":
GET http://{instance}/DefaultCollection/{project}/_apis/build/builds/{buildId}?api-version={version}
回答2:
So far, I end up with not clean workaround, but it were accepted by our management. I created two build definitions: one for gated-check in, one for CI. Once someone checked in something gated check-in fires. If it completed successfully, CI build would be triggered. Please note corresponding checkbox on UI:
This is not so clean solution, but it works for me.
来源:https://stackoverflow.com/questions/41763224/tfs-2015-the-var-sourcelocation-variable-is-not-available-at-gated-check-in