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

Committing to a New Branch to Github using Jenkins Octopus Deploy Plugin doesn't populate Commit Comments or VCSTypes #104

Open
5 tasks done
danefalvo opened this issue Apr 9, 2021 · 0 comments
Labels

Comments

@danefalvo
Copy link

Are you a customer of Octopus Deploy? Don't raise the issue here. Please contact our support team so we can triage your issue, making sure it's handled appropriately.

Prerequisites

  • I have verified the problem exists in the latest version
  • I have searched open and closed issues to make sure it isn't already reported
  • I have written a descriptive issue title
  • I have linked the original source of this report
  • I have tagged the issue appropriately (area/*, kind/bug, tag/regression?)

The bug

The Octopus Deploy plugin for Jenkins will not parse Commit comments or VcsType correctly if its the first commit to a new Github branch.

Any subsequent commits will parse the details correctly.

From the code, it looks as though the commit comments and VcsType are determined by the "Previous Build", on that particular branch. This means that there is no "Previous Build" for a new branch commit.

What I expected to happen

Initial commits on a branch should determine if they have branched off from a different tree and include those commits comments as well.

The VcsType should be determined from something other than the "Previous Build"

Steps to reproduce

  1. Create a Jenkins pipeline to push Build Information to an Octopus Instance.
  2. Make at least a couple of commits to the default branch.
  3. Use the pipeline to make the next commit to a new Branch.

Screen capture

First commit to a new branch
image

Subsequent commits
image

Affected versions

Jenkins plugin 3.1.3 tested.

Workarounds

None available.

Links

Original Ticket
https://help.octopus.com/t/build-information/26464

Link to relevant section in Code Repo - Public

private String getBuildInformationFromScm(Run<?, ?> build, EnvironmentVariableValueInjector envInjector, FilePath workspace) throws IOException, InterruptedException {
FilePath ws = workspace;
Job project = build.getParent();
String gitUrl = isNullOrEmpty(this.getGitUrl()) ? envInjector.injectEnvironmentVariableValues("${GIT_URL}") : envInjector.injectEnvironmentVariableValues(this.getGitUrl());
String gitCommit = isNullOrEmpty(this.getGitCommit())? envInjector.injectEnvironmentVariableValues("${GIT_COMMIT}") : envInjector.injectEnvironmentVariableValues(this.getGitCommit());
String gitBranch = isNullOrEmpty(this.getGitBranch())? envInjector.injectEnvironmentVariableValues("${GIT_BRANCH}") : envInjector.injectEnvironmentVariableValues(this.getGitBranch());
final OctopusBuildInformationBuilder builder = new OctopusBuildInformationBuilder();
final OctopusBuildInformation buildInformation = builder.build(
getVcsType(project),
gitUrl,
gitCommit,
getCommits(build, project),
commentParser,
envInjector.injectEnvironmentVariableValues("${BUILD_URL}"),
Integer.toString(build.getNumber()),
gitBranch
);
final String buildInformationFile = "octopus.buildinfo";
if (verboseLogging) {
log.info("Creating " + buildInformationFile + " in " + ws.getRemote());
}
final OctopusBuildInformationWriter writer = new OctopusBuildInformationWriter(log, verboseLogging);
writer.writeToFile(ws, buildInformation, buildInformationFile);
return buildInformationFile;
}
private String getVcsType(Job job) {
SCM scm;
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
scm = project.getScm();
}
else {
WorkflowJob workflowJob = (WorkflowJob) job;
scm = workflowJob.getTypicalSCM();
}
if (scm == null)
return "Unknown";
final String scmType = scm.getType().toLowerCase();
if (scmType.contains("git")) {
return "Git";
} else if (scmType.contains("cvs")) {
return "CVS";
}
return "Unknown";
}
private List<Commit> getCommits(Run<?,?> build, Job project) {
List<Commit> commits = new ArrayList<>();
Run lastSuccessfulBuild = project.getLastSuccessfulBuild();
Run currentBuild = null;
if (lastSuccessfulBuild == null) {
Run lastBuild = project.getLastBuild();
currentBuild = lastBuild;
}
else
{
currentBuild = lastSuccessfulBuild.getNextBuild();
}
if (currentBuild != null) {
while (currentBuild != build)
{
commits.addAll(convertChangeSetToCommits(currentBuild));
currentBuild = currentBuild.getNextBuild();
}
// Also include the current build
commits.addAll(convertChangeSetToCommits(build));
}
return commits;
}

@kengel100 kengel100 transferred this issue from OctopusDeploy/Issues Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants