-
Notifications
You must be signed in to change notification settings - Fork 402
Fix JENKINS-54249 #216
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
base: master
Are you sure you want to change the base?
Fix JENKINS-54249 #216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -47,10 +47,10 @@ | |
| </issueManagement> | ||
|
|
||
| <properties> | ||
| <jenkins.version>2.60.3</jenkins.version> | ||
| <jenkins.version>2.107.3</jenkins.version> | ||
| <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> | ||
|
|
@@ -62,7 +62,7 @@ | |
| <url>https://repo.jenkins-ci.org/public/</url> | ||
| </repository> | ||
| </repositories> | ||
|
|
||
| <pluginRepositories> | ||
| <pluginRepository> | ||
| <id>repo.jenkins-ci.org</id> | ||
|
|
@@ -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> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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> | ||
|
|
@@ -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> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for hard requiring newer dependency?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Here the version has been updated to be aligned with the version in use in library Otherwise the following error is displayed at Nervetheless I did not saw the comment Perhaps I could replace it by
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I do not remember doing any particular install which would bring this version installed to our Jenkins (that's why i supposed using version Do you know what reason could lead to the install of version
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because jenkins UpdateCenter treats
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bgaillard thank you for addressing this issue!
I'll comment on JENKINS-54249: it is not clear which issue you are actually submitting a fix for.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Would it be ok (i'll add clear comments to explain the intention in source code) ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reason?
There was a problem hiding this comment.
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.
This is because
org.jenkins-ci.plugins:git:4.0.0-rcusesorg.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).There was a problem hiding this comment.
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.