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 exception when invoked from TFS Release Management (JENKINS-40283) #142

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions tfs/src/main/java/hudson/plugins/tfs/model/BuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
Expand Down Expand Up @@ -209,23 +210,27 @@ static void contributeTeamBuildParameterActions(final Map<String, String> teamBu
final boolean isTeamGit = "TfGit".equalsIgnoreCase(provider)
|| "TfsGit".equalsIgnoreCase(provider);
if (isTeamGit) {
final String collectionUriString = teamBuildParameters.get(SYSTEM_TEAM_FOUNDATION_COLLECTION_URI);
final URI collectionUri = URI.create(collectionUriString);
// "Build.Repository.Uri" is null/whitespace/empty when the 'Jenkins Queue Job' task runs in TFS Release Management.
// In this case, do not reference a CommitParameterAction in the actions reported as unsupported.
final String repoUriString = teamBuildParameters.get(BUILD_REPOSITORY_URI);
final URI repoUri = URI.create(repoUriString);
final String projectId = teamBuildParameters.get(SYSTEM_TEAM_PROJECT);
final String repoId = teamBuildParameters.get(BUILD_REPOSITORY_NAME);
final String commit = teamBuildParameters.get(BUILD_SOURCE_VERSION);
final String pushedBy = teamBuildParameters.get(BUILD_REQUESTED_FOR);
final GitCodePushedEventArgs args = new GitCodePushedEventArgs();
args.collectionUri = collectionUri;
args.repoUri = repoUri;
args.projectId = projectId;
args.repoId = repoId;
args.commit = commit;
args.pushedBy = pushedBy;
final CommitParameterAction action = new CommitParameterAction(args);
actions.add(action);
if (StringUtils.isNotBlank(repoUriString)) {
final URI repoUri = URI.create(repoUriString);
final String collectionUriString = teamBuildParameters.get(SYSTEM_TEAM_FOUNDATION_COLLECTION_URI);
final URI collectionUri = URI.create(collectionUriString);
final String projectId = teamBuildParameters.get(SYSTEM_TEAM_PROJECT);
final String repoId = teamBuildParameters.get(BUILD_REPOSITORY_NAME);
final String commit = teamBuildParameters.get(BUILD_SOURCE_VERSION);
final String pushedBy = teamBuildParameters.get(BUILD_REQUESTED_FOR);
final GitCodePushedEventArgs args = new GitCodePushedEventArgs();
args.collectionUri = collectionUri;
args.repoUri = repoUri;
args.projectId = projectId;
args.repoId = repoId;
args.commit = commit;
args.pushedBy = pushedBy;
final CommitParameterAction action = new CommitParameterAction(args);
actions.add(action);
}

UnsupportedIntegrationAction.addToBuild(actions, "Posting build status is not supported for builds triggered by the 'Jenkins Queue Job' task.");
}
Expand Down