Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tfs push bug #1

Closed
wants to merge 11 commits into from
Closed

Fix tfs push bug #1

wants to merge 11 commits into from

Conversation

smile21prc
Copy link
Owner

@smile21prc smile21prc commented Jun 22, 2017

The fix is ready, which basically:

  1. Handles the case when SCM configuration of a job is empty, which was the
    root cause of the previous random TFS push trigger failure.

  2. Add an additional case when a job should be executed – the commit is NOT
    null:
    a. runPolling() actually checks SCM changes, which in our cases are
    none.
    b. As long as a commit in linked repro triggers this push (commit is NOT
    null), the job should be executed.

  3. Refactors original trigger logic into function “triggerJob”, to avoid
    dupe code as these code will be called twice in AbstractHookEvent.java.

  4. I removed existing code in AbstractHookEvent.java, which goes through all SCMs and Repos and might still be applied to some old free style projects. This is because its logic is dupe with the one in runPolling().

Now if you merge any change to dotnet-linker/enable-ci, all four jobs
starting with “testing” (on link below) will be triggered, and ONLY
those three will be triggered.

https://dotnet-vsts.westus2.cloudapp.azure.com/job/DevDiv_dotnet-linker/job/enable-ci/

The fix is ready, which basically:

Handles the case when SCM configuration of a job is empty, which was the
root cause of the previous random TFS push trigger failure.
Add an additional case when a job should be executed – the commit is NOT
null:
a. runPolling() actually checks SCM changes, which in our cases are
none.
b. As long as a commit in linked repro triggers this push (commit is NOT
null), the job should be executed.
Refactors original trigger logic into function “triggerJob”, to avoid
dupe code as these code will be called twice in AbstractHookEvent.java.
I choose not to remove existing code in AbstractHookEvent.java, which
goes through all SCMs and Repos and might still be applied to some old
free style projects. Instead I add the handling of the missing cases
(when SCM configuration of a job is empty) on top of it.

Now if you merge any change to dotnet-linker/enable-ci, all four jobs
starting with “testing” (on link below) will be triggered, and ONLY
those three will be triggered.

https://dotnet-vsts.westus2.cloudapp.azure.com/job/DevDiv_dotnet-linker/job/enable-ci/
Cleanup
Still need this iteration to filter out unwanted runs.
Clean up spaces
This reverts commit 38d1c0f.
@smile21prc smile21prc self-assigned this Jun 22, 2017
Remove unnecessary continue
@@ -119,13 +119,13 @@ public void run() {
boolean shouldSchedule = bypassPolling;
String changesDetected = "";
if (!bypassPolling) {
if (runPolling()) {
if (runPolling() || gitCodePushedEventArgs.commit != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer...
|| StringUtils.isNotBlank(gitCodePushedEventArgs.commit)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion Jason, I'll fix and verify it.

Address review comments.
@jpricket
Copy link

@smile21prc - I few things about process:

  1. Please squash your commits (this will make history easier to follow)
  2. Add appropriate Unit Tests for any new features (I don't think you need any for this change)
  3. To create a PR against the tfs-plugin repo, push your commit to your master branch in this repo and create a PR against the master branch in the tfs-plugin repo. This will create a PR in the other repo that can then be merged.
  4. Make sure that the Jenkins builds pass. If not, please correct any issues and update the master branch here with the fixes. This will automatically update the PR.

Thanks for this contribution!

@jpricket
Copy link

@smile21prc - when the new PR is ready in the tfs-plugin branch, I will review it and merge it when ready.

@smile21prc
Copy link
Owner Author

@jpricketMSFT , thanks for the review and instructions about the process. I'll follow your instructions and let you know when the new PR is ready.

Add import of StringUtils.
@smile21prc
Copy link
Owner Author

@mmitche , I've verified our jobs can constantly be triggered now by any push in enable-ci branch after addressing Jason's comment. Any additional comment before I merge into my private master branch?

@mmitche
Copy link

mmitche commented Jun 23, 2017

@smile21prc I wouldn't merge this into your private master. This should just be a PR to jenkinsci/tfs-plugin.

I'll take a look at this later.

@smile21prc
Copy link
Owner Author

Thanks @mmitche , I'll hold it till you take a look.


if (!(project instanceof AbstractProject && ((AbstractProject) project).isDisabled())) {
if (project instanceof Job) {
// TODO: Add default parameters defined in the job
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really not queueing it with parameters?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the jobs being kicked off do use customized params, so this comment isn't needed any more, removed it.

final int quietPeriod = scmTriggerItem.getQuietPeriod();

boolean triggered = false;
if (!triggered) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always false here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is the code from original plugin. I've removed this unnecessary if statement.

final SCMTrigger scmTrigger = TeamEventsEndpoint.findTrigger(job, SCMTrigger.class);
if (scmTrigger != null && scmTrigger.isIgnorePostCommitHooks()) {
// job has explicitly opted out of hooks
triggered = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of use of triggered in here in sort of confusing ways. I think the if (triggered) block below should be inlined into this block (invert the above if condition), returning the new gitResponse directly rather than waiting for the end of the series of if statements.

Copy link
Owner Author

@smile21prc smile21prc Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refined the logic, and removed "triggered" var entirely as it becomes unnecessary. Also changed to return directly instead of waiting.

}
}
}
if (!triggered) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you inline the if (triggered) block, then this if (!triggered) becomes unnecessary since it's always false if you get here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, removed "triggered" var entirely as it becomes unnecessary.

final Action[] actionArray = ActionHelper.create(actions, causeAction);
scmTriggerItem.scheduleBuild2(quietPeriod, actionArray);
gitResponse = new TeamEventsEndpoint.ScheduledResponseContributor(project);
triggered = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again you could just return gitResponse directly from this block

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, did that.

triggered = true;
}
}
if (!triggered) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which would make this always false again.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, removed this unnecessary statement.

else {
gitResponse = new TeamEventsEndpoint.PollingScheduledResponseContributor(project);
}
triggered = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again return directly from this

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -119,13 +120,13 @@ public void run() {
boolean shouldSchedule = bypassPolling;
String changesDetected = "";
if (!bypassPolling) {
if (runPolling()) {
if (runPolling() || StringUtils.isNotBlank(gitCodePushedEventArgs.commit)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here to indicate why the gitCodePushedEventArgs is needed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added comments below:
// pipeline jobs might have runPolling() returned as false, while still should be scheduled.
// we should shedule them as long as they are associated with a valid commit.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why runPolling returns false in those cases?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and if so, can you add it as a comment here too)

Addressed Matt's comments.
Addressed more of Matt's comments.
@smile21prc
Copy link
Owner Author

Addressed all comments, and re-created this PR as below against the branch to be merged (master in jenkinsci/tfs-plugin)
jenkinsci#164

@smile21prc smile21prc closed this Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants