Skip to content

Commit

Permalink
Merge pull request #142 from jenkinsci/users/davidstaheli/rm1
Browse files Browse the repository at this point in the history
Fix exception when invoked from TFS Release Management (JENKINS-40283)
  • Loading branch information
davidstaheli committed Dec 8, 2016
2 parents 29594a6 + 68353ee commit aa7b022
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions tfs/src/main/java/hudson/plugins/tfs/model/BuildCommand.java
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

0 comments on commit aa7b022

Please sign in to comment.