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

Update VSTS PR Jenkins build status back to VSTS #175

Merged
merged 21 commits into from
Sep 27, 2017

Conversation

smile21prc
Copy link
Contributor

Update VSTS PR Jenkins build status back to VSTS.

Re-target the PR smile21prc#2 to official plug-in branch.

Add jelly support
…pdate.

Add a seperate checkbox for PR trigger, and fully enable its status update.
Remove redundant entry in pom
@smile21prc
Copy link
Contributor Author

+@mmitche @jpricketMSFT
Based on @mmitche's suggestion, I've made added changes below on top of previous PRs:

  1. Added a separate checkbox for PR Trigger, so customers can choose to subscribe notifications for either TFS push or TFS PR commit, or both.
    bothtriggers

  2. Changed to use textbox from above UIs to specify names showing in VSTS status, instead of composing them with random customized tags like AGroup.

  3. Made sure only runs kicked off by PR commit will show status update in corresponding PRs, while those runs kicked off code push will NOT.

  4. Enabled CHECKSTYLE in multiple sources and fixed their formats.

@smile21prc
Copy link
Contributor Author

Deployed the plugin to https://dotnet-vsts.westus2.cloudapp.azure.com, which worked well -- runs are correctly triggered by both PR commit and code push based on their configurations.

List<T> triggerList = new ArrayList<>();
if (job instanceof ParameterizedJobMixIn.ParameterizedJob) {
final ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) job;
for (final Trigger trigger : pJob.getTriggers().values()) {
Copy link

Choose a reason for hiding this comment

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

Is there not a getTriggers on non ParameterizedJobs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nop, I don't see one in its member list, if a job isn't a ParameterizedJob:

jobgetfunclist

@@ -12,19 +12,22 @@
public class TeamPushCause extends SCMTriggerCause {

private final String pushedBy;
private final String runConfig;
Copy link

Choose a reason for hiding this comment

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

Can you refactor this name to "context" just for consistency with other plugins that do similar things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, refactored it "context".

@@ -48,6 +49,9 @@ public TeamPushTrigger(final Job<?, ?> job) {
this.job = job;
Copy link

Choose a reason for hiding this comment

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

In a future PR we should figure out whether this constructor can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will try that out in the PR to add refspec param into TeamPushTrigger.

Copy link

Choose a reason for hiding this comment

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

Okay sounds good. It might be good for the trigger to inject a parameter for both the refspec and the hash. That way the same job can be used for both PRs and pushes if desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Matt. I tried multiple approaches and chose the environment contributor approach which worked locally. Now both values (vstsRefspec and vstsBranch) are shown in the "Parameters" tab on build page, and it's loadable in triggered builds.

image

}
}
}
return "Jenkins CI build";
Copy link

Choose a reason for hiding this comment

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

Can you pull this string out into a static constant somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Refactored it as a static constant in JenkinsRunListener class:
private static final String DEFAULT_RUN_CONTEXT = "Jenkins CI build";

}

private Boolean repoMatch(final GitCodePushedEventArgs gitCodePushedEventArgs, final Job job) {
if (job instanceof WorkflowJob) {
Copy link

Choose a reason for hiding this comment

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

I assume this work for non workflow jobs?

Copy link
Contributor Author

@smile21prc smile21prc Sep 20, 2017

Choose a reason for hiding this comment

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

Good catch. Non-workflow jobs do repo matching check first, and calls triggerJob() only if it matches (in pullOrQueueFromEvent()), but we do need a var in triggerJob() to know the status of "this is a non-workflow job whose repo already matches).

Added a new param "final Boolean repoMatch" to triggerJob() to signal that status.

<!--
The MIT License

Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
Copy link

Choose a reason for hiding this comment

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

Copyright header should be an MS copyright.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the whole file.

@@ -0,0 +1,45 @@
<!--
Copy link

Choose a reason for hiding this comment

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

What's the reason for this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's cloned from TeamPushTrigger. Turns out it's redudant for TeamPRPushTrigger -- it worked fine after removing it. So I've removed the whole file.

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">>
<f:entry title="Job Context" field="jobContext">
<f:textbox default="Jenkins CI build" />
Copy link

Choose a reason for hiding this comment

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

CI doesn't necessarily imply PR. Can you change this to "Jenkins PR Build"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, changed.

Address review comments.
@smile21prc
Copy link
Contributor Author

Thanks for the review @mmitche, and I've addressed all your comments. Can you take another look at your convenient time? Thanks.

}
}
} catch (final Exception e) {
e.printStackTrace();
Copy link

Choose a reason for hiding this comment

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

These errors here should be sent to the logger (https://github.com/jenkinsci/tfs-plugin/pull/175/files#diff-462c46539e78a70b95caa4cf430ecbd7R39) so they are easy to find and filter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

final TeamRestClient client = new TeamRestClient(collectionUri);
client.addPullRequestStatus(gitCodePushedEventArgs, status);
} catch (MalformedURLException e) {
e.printStackTrace();
Copy link

Choose a reason for hiding this comment

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

These errors here should be sent to the logger (https://github.com/jenkinsci/tfs-plugin/pull/175/files#diff-462c46539e78a70b95caa4cf430ecbd7R39) so they are easy to find and filter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
Copy link

Choose a reason for hiding this comment

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

These errors here should be sent to the logger (https://github.com/jenkinsci/tfs-plugin/pull/175/files#diff-462c46539e78a70b95caa4cf430ecbd7R39) so they are easy to find and filter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -48,6 +49,9 @@ public TeamPushTrigger(final Job<?, ?> job) {
this.job = job;
Copy link

Choose a reason for hiding this comment

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

Okay sounds good. It might be good for the trigger to inject a parameter for both the refspec and the hash. That way the same job can be used for both PRs and pushes if desired.

return new JSONObject();
}

private String getRunContext(final Run run) {
Copy link

Choose a reason for hiding this comment

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

Why is this code here workflow job specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. It shouldn't. I've changed it to be applied to all jobs.

Address review comments.
Pass additional params to Jenkins build for PR job auto-gen
Renaming to vstsBranchOrCommit
@smile21prc
Copy link
Contributor Author

@mmitche, any further comments on this PR?

Add constructor to allow creating a job trigger with job context param.
@mosabua
Copy link
Member

mosabua commented Sep 26, 2017

When this is merged please ensure to do a squash merge to ensure a relatively clean history.

@smile21prc
Copy link
Contributor Author

@mosabua , sure will.

@smile21prc
Copy link
Contributor Author

smile21prc commented Sep 26, 2017

Hi, @jpricketMSFT, seems I don't have enough access to add you as the reviewer of this PR. There are a bunch of changes after your previous sign-off. If you've got any additional comments, please feel free to let me know. Thanks.

I've deployed it to https://dotnet-vsts.westus2.cloudapp.azure.com/job/DevDiv_dotnet-linker, and verified both PR and Push trigger & VSTS status update worked well -- https://dotnet-vsts.westus2.cloudapp.azure.com/job/DevDiv_dotnet-linker/job/TestJobs/.

Added support of branch-specific triggering for both PR and code push
@smile21prc
Copy link
Contributor Author

smile21prc commented Sep 27, 2017

@mmitche, added support on branch-specific triggering.

PR merge jobs now are only triggered when PR happens in the branch list of PR trigger UI:
branch_trigger_pr

While code push jobs are triggered when code push happens in a branch matching one of its Git branches:
branch_trigger_codepush

@jpricket jpricket self-requested a review September 27, 2017 13:51
@jpricket jpricket assigned jpricket and unassigned jpricket Sep 27, 2017
Copy link
Contributor

@jpricket jpricket left a comment

Choose a reason for hiding this comment

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

I don't see any major problems. This is a large PR, so we will do extra regression testing before releasing these changes to make sure that the other plugin features are not affected.

@jpricket jpricket merged commit 102f112 into jenkinsci:master Sep 27, 2017
@smile21prc
Copy link
Contributor Author

Thanks @jpricketMSFT .

@smile21prc smile21prc deleted the pr_status branch September 27, 2017 17:54
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.

4 participants