Skip to content

Commit

Permalink
[JENKINS-75208] Checkout on bitbucket server fail with IllegalArgumen…
Browse files Browse the repository at this point in the history
…tException "Name cannot contain '/'" (#986)

Fix Bitbucket Cloud client when getFile metadata has path attribute value that contains '/', for example 'scripts/Jenkinsfile' that cause a failure when build the SCMFile to return.
  • Loading branch information
nfalco79 authored Feb 6, 2025
1 parent dec3fc3 commit bdca4ab
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public BitbucketSCMFile toBitbucketSCMFile(BitbucketSCMFile parent) {
}
}
}
return new BitbucketSCMFile(parent, path, fileType, hash);
return parent.child(path, fileType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.io.InputStream;
import java.util.Collections;
import jenkins.scm.api.SCMFile;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

public class BitbucketSCMFile extends SCMFile {

Expand Down Expand Up @@ -69,6 +71,11 @@ public String getHash() {
return hash;
}

@Restricted(NoExternalUse.class)
public void setType(Type type) {
type(type);
}

@Override
@NonNull
public Iterable<SCMFile> children() throws IOException, InterruptedException {
Expand Down Expand Up @@ -101,6 +108,14 @@ protected SCMFile newChild(String name, boolean assumeIsDirectory) {
return new BitbucketSCMFile(this, name, null, hash);
}

@NonNull
public BitbucketSCMFile child(@NonNull String path, @NonNull Type type) {
BitbucketSCMFile scmFile = (BitbucketSCMFile) super.child(path);
scmFile.type(type);
scmFile.resolved = true;
return scmFile;
}

@Override
@NonNull
protected Type type() throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ void test_SCMFile_does_not_contains_illegal_chars_in_the_name() throws Exception
});
}

@Issue("JENKINS-75208")
@Test
void test_SCMFile_when_client_return_path_attribute_with_folder_separator_on_cloud() throws Exception {
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient("https://bitbucket.org");

BitbucketSCMFile root = new BitbucketSCMFile(client, "master", null);
SCMFile file = root.child("folder/file.properties");
String content = file.contentAsString();
assertThat(content).isEqualTo("message=This is a test for metadata");
}

@Issue("JENKINS-75157")
@Test
void test_SCMBinder_behavior_when_discover_the_Jenkinsfile_for_a_given_branch_on_cloud() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message=This is a test for metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"path": "folder/file.properties",
"commit": {
"hash": "e43fdffe2def75053da30efa8204d0317a0b932a",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/commit/e43fdffe2def75053da30efa8204d0317a0b932a"
},
"html": {
"href": "https://bitbucket.org/amuniz/test-repos/commits/e43fdffe2def75053da30efa8204d0317a0b932a"
}
},
"type": "commit"
},
"type": "commit_file",
"attributes": [],
"escaped_path": "folder/file.properties",
"size": 35,
"mimetype": null,
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/src/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties"
},
"meta": {
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/src/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties?format=meta"
},
"history": {
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/filehistory/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties"
}
}
}

0 comments on commit bdca4ab

Please sign in to comment.