-
Notifications
You must be signed in to change notification settings - Fork 354
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
JENKINS-48737 Adding lightweight checkouts for Bitbucket Pull Requests #117
Conversation
#114 seems to make more sense than this fix as it fixes the source issue |
String ref; | ||
if(file.getRef().matches("PR-\\d+")) { // because JENKINS-48737 | ||
String prId = file.getRef().replace("PR-", ""); | ||
ref = "refs/pull-requests/" + prId + "/from"; |
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.
Could respect the pull request merge strategy set on the build configuration
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.
agree with @Casz, could we use pull-requests/id/merge
as ref for merge strategy?
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.
indeed, which I was hinting at 👍
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.
Thanks for the feedback. I will pick up your comments. Hopefully I have time this week. 👍
26b9f6a
to
3bac95e
Compare
We are affected by this issue, too. Any plans for next release? |
fcb4ed0
to
1e7dbf8
Compare
So I tested it in our environment. It is working but this print is now wrong "Obtained Jenkinsfile from XXXX" since it should mention, that it used the merge ref. |
@benjaminfuchs see #114 |
@Casz If 114 also fixes this issue and gets merged I'm also fine with that. Is this done with the next release? |
What is missing for getting this merged? This is blocker for us. |
As far as I can tell #114 fixes this issue for the "current pull request revision" strategy but it doesn't fix it for the "merge" strategy. Correct me please @benjaminfuchs |
@tarioch Yes #114 will fix the "current pull request revision" but not the "merge" strategy. I think the "merge" strategy is the most common use-case, so I guess this pull request should be merged independent from #114. |
@benjaminfuchs I think after #114 is merged the first part
would need to be changed because I think that would then be the branch name of the PR. |
Any updates? |
I'll try and look into this and #114 |
@benjaminfuchs please look into it 👍 |
any ETA on this? |
@benjaminfuchs I checked and PR still does full checkouts. This needs to adapt: Lines 137 to 141 in f442c48
|
Actually |
@Override
public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision rev)
throws IOException, InterruptedException {
BitbucketSCMSource src = (BitbucketSCMSource) source;
String credentialsId = src.getCredentialsId();
String owner = src.getRepoOwner();
String repository = src.getRepository();
String serverUrl = src.getServerUrl();
StandardUsernamePasswordCredentials credentials;
credentials = lookupScanCredentials(src.getOwner(), credentialsId);
BitbucketApi apiClient = BitbucketApiFactory.newInstance(serverUrl, credentials, owner, repository);
String ref;
if (head instanceof BranchSCMHead) {
ref = head.getName();
} else if (head instanceof PullRequestSCMHead) {
PullRequestSCMHead pr = (PullRequestSCMHead) head;
String checkoutStrat = "from";
if (pr.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.MERGE) {
checkoutStrat = "merge";
}
ref = "refs/pull-requests/" + pr.getId() + "/" + checkoutStrat;
} else if (head instanceof BitbucketTagSCMHead) {
ref = "tags/" + head.getName();
} else {
return null;
}
return new BitbucketSCMFileSystem(apiClient, ref, rev);
} works out nicely 😅 |
@Casz We are currently using my patched plugin and it works fine. Your change also looks reasonable. How should we continue? |
sadly does not work for cloud
|
@Casz I guess my changes only work if you set "Discover pull requests from origin" to Strategy "The current pull requets revision". EDIT: Its not a guess, just downloaded the latest jenkins build result here and can confirm. Only works with that setting. Why, currently dont know. |
I guess we have to check api client if server or cloud for now... until we can find a solution for cloud too |
with the changes from #114 this did not work at least the current state 😅 |
@benjaminfuchs if you could adapt the PR and the tests to: if (head instanceof BranchSCMHead) {
ref = head.getName();
} else if (head instanceof PullRequestSCMHead) {
PullRequestSCMHead pr = (PullRequestSCMHead) head;
if (apiClient instanceof BitbucketCloudApiClient) {
if (!(pr.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.MERGE) && pr.getRepository() != null) {
return new BitbucketSCMFileSystem(apiClient, pr.getOriginName(), rev);
}
return null; // TODO support merge revisions somehow for cloud
}
String checkoutStrategy = "from";
if (pr.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.MERGE) {
checkoutStrategy = "merge";
}
ref = "refs/pull-requests/" + pr.getId() + "/" + checkoutStrategy;
} else if (head instanceof BitbucketTagSCMHead) {
ref = "tags/" + head.getName();
} else {
return null;
} I would appreciate it 😇🙌 |
@CheckForNull | ||
private ChangeRequestCheckoutStrategy getCheckoutStrategy() throws IOException, InterruptedException { | ||
if (this.isDirectory()) { | ||
SCMRevision revision = fileSystem.getRevision(); |
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.
Any ETA for this very important feature? |
@bjornmagnusson if you feel it is important, feel free to rework the PR. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Superseded by #174 |
Proposing a fix for https://issues.jenkins-ci.org/browse/JENKINS-48737
Tested on our Bitbucket -> Jenkins setup.