Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 7 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.coravy.hudson.plugins.github</groupId>
<artifactId>github</artifactId>
<version>1.29.5-SNAPSHOT</version>
<version>1.30.0-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>GitHub plugin</name>
Expand Down Expand Up @@ -47,10 +47,10 @@
</issueManagement>

<properties>
<jenkins.version>2.60.3</jenkins.version>
<jenkins.version>2.107.3</jenkins.version>
Copy link
Member

Choose a reason for hiding this comment

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

reason?

Copy link
Author

Choose a reason for hiding this comment

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

Otherwise the following exception is encountered while executing the tests.

[ERROR] Tests run: 53, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 9.07 s <<< FAILURE! - in InjectedTest
[ERROR] testPluginActive(org.jvnet.hudson.test.PluginAutomaticTestBuilder$OtherTests)  Time elapsed: 0.006 s  <<< ERROR!
java.lang.Error: Plugin git-client failed to start
        at org.jvnet.hudson.test.PluginAutomaticTestBuilder$OtherTests.testPluginActive(PluginAutomaticTestBuilder.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...
...
Caused by: java.io.IOException: Jenkins Git client plugin v3.0.0-rc failed to load.
 - You must update Jenkins from v2.60.3 to v2.107.3 or later to run this plugin.
        at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:626)
        at hudson.PluginManager$2$1$1.run(PluginManager.java:516)
        at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
        at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
        at jenkins.model.Jenkins$7.runTask(Jenkins.java:1090)
        at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
        at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
        ... 3 more

This is because org.jenkins-ci.plugins:git:4.0.0-rc uses org.jenkins-ci.plugins:git-client:3.0.0-rc (see https://github.com/jenkinsci/git-plugin/blob/git-4.0.0-rc/pom.xml#L83).

Copy link
Member

Choose a reason for hiding this comment

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

so all bumps because of git rc version, ok.

<release.skipTests>false</release.skipTests>
<maven.javadoc.skip>true</maven.javadoc.skip>
<findbugs-maven-plugin.version>3.0.2</findbugs-maven-plugin.version>
<findbugs-maven-plugin.version>3.0.5</findbugs-maven-plugin.version>
<concurrency>1</concurrency>
<java.level>8</java.level>
<workflow.version>1.14.2</workflow.version>
Expand All @@ -62,7 +62,7 @@
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
Expand Down Expand Up @@ -99,13 +99,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>3.4.0</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.0</version>
<version>4.0.0-rc</version>
Copy link
Member

Choose a reason for hiding this comment

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

Too new dependency, github plugin wouldn't lock users to have release candidate as hard dependency.

</dependency>

<dependency>
Expand All @@ -129,7 +123,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.12.1</version>
<version>2.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -157,7 +151,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<version>4.5.3-2.1</version>
<version>4.5.5-3.0</version>
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for hard requiring newer dependency?

Copy link
Author

@bgaillard bgaillard Jun 16, 2019

Choose a reason for hiding this comment

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

Hi @KostyaSha and thanks for your reactivity reviewing this PR 👍

The purpose of the PR is to make the github-plugin compliant with last versions of the git Jenkins plugin (current version 4.0.0-rc).

Here the version has been updated to be aligned with the version in use in library org.jenkins-ci.plugins:git:4.0.0-rc.

Otherwise the following error is displayed at mvn install .

[WARNING] Rule 4: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.jenkins-ci.plugins:apache-httpcomponents-client-4-api:4.5.3-2.1 paths to dependency are:
+-com.coravy.hudson.plugins.github:github:1.30.0-SNAPSHOT
  +-org.jenkins-ci.plugins:apache-httpcomponents-client-4-api:4.5.3-2.1
and
+-com.coravy.hudson.plugins.github:github:1.30.0-SNAPSHOT
  +-org.jenkins-ci.plugins:git:4.0.0-rc
    +-org.jenkins-ci.plugins:git-client:3.0.0-rc
      +-org.jenkins-ci.plugins:apache-httpcomponents-client-4-api:4.5.5-3.0

Nervetheless I did not saw the comment <!-- 4.5.3 used by rest-assured --> above the dependency declaration in the pom.xml.

Perhaps I could replace it by <!-- 4.5.3-3.0 used by org.jenkins-ci.plugins:git:4.0.0-rc --> ?

Copy link
Member

Choose a reason for hiding this comment

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

i don't think that 4.0.0-rc will be used in the nearest half year/year. This plugin is used on a lot of installations that will have no chance to update. If there is something really broken then it need to be fixed with the current code base...

Copy link
Author

Choose a reason for hiding this comment

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

Ok I understand.

But i'm a little confused with my current Jenkins install, the current version of the git plugin installed on our server is version 4.0.0-rc.

I do not remember doing any particular install which would bring this version installed to our Jenkins (that's why i supposed using version 4.0.0-rc in this PR would be ok).

Do you know what reason could lead to the install of version 4.0.0-rc on our Jenkins server ? Could this be because of the install of an other plugin ? In this case is it possible to find what plugins use this version 4.0.0-rc ?

Copy link
Member

@KostyaSha KostyaSha Jun 17, 2019

Choose a reason for hiding this comment

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

because jenkins UpdateCenter treats -rc as stable version. From experience git plugin had enough issues even between released versions and user may need to have ability to install the variety of versions. There is no need to have too fresh hard dep on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bgaillard thank you for addressing this issue!
BTW, we're encountering the same issue symptom with lower plugin versions (see NXBT-2867).
Our current versions are:

  • CloudBees Jenkins Enterprise 2.164.3.2-rolling
  • Git client plugin 2.7.6
  • Git plugin 3.9.3
  • SCM API Plugin 2.4.0

I'll comment on JENKINS-54249: it is not clear which issue you are actually submitting a fix for.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @jcarsique, I responded you here : https://issues.jenkins-ci.org/browse/JENKINS-54249

@KostyaSha, ok perhaps it's possible to update my PR to not depend on version 4.0.0-rc of git-plugin but I think it will require "ugly" tricks using reflection and i'll not be able to unit test it because the BuildDetails class will not be available.

Would it be ok (i'll add clear comments to explain the intention in source code) ?

Copy link
Member

Choose a reason for hiding this comment

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

first of all restore binary compatibility, don't rename any java classes just to rename them. If you want to add new utils, then deprecate old...
I saw in issue that problem appeared since X version of plugin, is it possible to revert this piece of functionality?

Copy link
Author

Choose a reason for hiding this comment

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

I think I can restore all library versions and make the plugin compliant with version 4.0.x of git-plugin without depending on it but it will be an "ugly" fix.

I'll need to use reflection to get informations from the BuildDetails class at runtime to then rebuild a BuildData object.

So I think the main problem is that Jenkins should not have proposed to install an RC version.

In the JIRA issue other users suggest to downgrade. Perhaps it's possible in some situations to downgrade but not always (because we could have other plugin depending on git-plugin 4.0.x and our jobs could use new features of those other plugins, making the downgrade of the other plugins not possible).

IMO and ideally Jenkins and it's libraries and plugins should respect something like SEMVER and be strict with it. But perhaps this would not solve everything... anyway we are on a standard Java JAR hell problem.

<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hudson.model.TaskListener;
import org.eclipse.jgit.lib.ObjectId;
import org.jenkinsci.plugins.github.extension.status.GitHubCommitShaSource;
import org.jenkinsci.plugins.github.util.BuildDataHelper;
import org.jenkinsci.plugins.github.util.BuildDetailsHelper;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;
Expand All @@ -29,7 +29,7 @@ public BuildDataRevisionShaSource() {
*/
@Override
public String get(@Nonnull Run<?, ?> run, @Nonnull TaskListener listener) throws IOException {
return ObjectId.toString(BuildDataHelper.getCommitSHA1(run));
return ObjectId.toString(BuildDetailsHelper.getCommitSHA1(run));
}

@Extension
Expand Down
105 changes: 0 additions & 105 deletions src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.jenkinsci.plugins.github.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

import org.eclipse.jgit.lib.ObjectId;

import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.git.Revision;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.util.Build;
import hudson.plugins.git.util.BuildData;
import hudson.plugins.git.util.BuildDetails;

/**
* Stores common methods for {@link BuildDetails} handling.
*
* @author Baptiste Gaillard <baptiste.gaillard@gmail.com>
* @since 1.30.0
*/
public final class BuildDetailsHelper {

private BuildDetailsHelper() {
}

/**
* Calculate build data from downstream builds, that could be a shared library which is loaded first in a pipeline.
* For that reason, this method compares all remote URLs for each build data, with the real project name, to
* determine the proper build data. This way, the SHA returned in the build data will relate to the project.
*
* @param parentName name of the parent build.
* @param parentFullName full name of the parent build.
* @param buildDetailsList the list of build details from a build run.
*
* @return the build data related to the project, null if not found.
*/
public static BuildDetails calculateBuildDetails(
String parentName, String parentFullName, List<BuildDetails> buildDetailsList
) {
if (buildDetailsList == null) {
return null;
}

if (buildDetailsList.size() == 1) {
return buildDetailsList.get(0);
}

String projectName = parentFullName.replace(parentName, "");

if (projectName.endsWith("/")) {
projectName = projectName.substring(0, projectName.lastIndexOf('/'));
}

for (BuildDetails buildDetails : buildDetailsList) {
Set<String> remoteUrls = buildDetails.getRemoteUrls();

for (String remoteUrl : remoteUrls) {
if (remoteUrl.contains(projectName)) {
return buildDetails;
}
}
}

return null;
}

/**
* Gets SHA1 from the build.
*
* @param build
*
* @return SHA1 of the last build.
*
* @throws IOException Cannot get the info about commit ID.
*/
@Nonnull
public static ObjectId getCommitSHA1(@Nonnull Run<?, ?> build) throws IOException {

Job<?, ?> parent = build.getParent();

List<BuildDetails> buildDetailsList = build.getActions(BuildDetails.class);

// If we cannot get build data from a 'BuildDetails' action then we try to get it from a 'BuildData' action.
// This should not be possible in the future as the 'BuildData' class will be deprecated.
if (buildDetailsList.isEmpty()) {
buildDetailsList = new ArrayList<>();

for (BuildData buildData : build.getActions(BuildData.class)) {
Collection<UserRemoteConfig> remoteConfigs = new ArrayList<>();

for (String url : buildData.getRemoteUrls()) {
remoteConfigs.add(new UserRemoteConfig(url, null, null, null));
}

buildDetailsList.add(new BuildDetails(buildData.lastBuild, buildData.scmName, remoteConfigs));
}
}

BuildDetails buildDetails = calculateBuildDetails(parent.getName(), parent.getFullName(), buildDetailsList);

if (buildDetails == null) {
throw new IOException(Messages.BuildDetailsHelper_NoBuildDataError());
}

// buildData?.lastBuild?.marked and fall back to .revision with null check everywhere to be defensive
Build b = buildDetails.getBuild();
if (b != null) {
Revision r = b.marked;
if (r == null) {
r = b.revision;
}
if (r != null) {
return r.getSha1();
}
}

// Nowhere to report => fail the build
throw new IOException(Messages.BuildDetailsHelper_NoLastRevisionError());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static <T extends Trigger> T triggerFrom(Item item, Class<T> tClass) {
if (item instanceof ParameterizedJobMixIn.ParameterizedJob) {
ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) item;

for (Trigger candidate : pJob.getTriggers().values()) {
for (Object candidate : pJob.getTriggers().values()) {
if (tClass.isInstance(candidate)) {
return tClass.cast(candidate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BuildDataHelper.NoBuildDataError=Cannot retrieve Git metadata for the build
BuildDataHelper.NoLastRevisionError=Cannot determine sha1 of the commit. The status cannot be reported
BuildDetailsHelper.NoBuildDataError=Cannot retrieve Git metadata for the build
BuildDetailsHelper.NoLastRevisionError=Cannot determine sha1 of the commit. The status cannot be reported
Loading