Skip to content

Commit bdca4ab

Browse files
authored
[JENKINS-75208] Checkout on bitbucket server fail with IllegalArgumentException "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.
1 parent dec3fc3 commit bdca4ab

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/repository/BitbucketRepositorySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public BitbucketSCMFile toBitbucketSCMFile(BitbucketSCMFile parent) {
8787
}
8888
}
8989
}
90-
return new BitbucketSCMFile(parent, path, fileType, hash);
90+
return parent.child(path, fileType);
9191
}
9292

9393
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFile.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.io.InputStream;
3232
import java.util.Collections;
3333
import jenkins.scm.api.SCMFile;
34+
import org.kohsuke.accmod.Restricted;
35+
import org.kohsuke.accmod.restrictions.NoExternalUse;
3436

3537
public class BitbucketSCMFile extends SCMFile {
3638

@@ -69,6 +71,11 @@ public String getHash() {
6971
return hash;
7072
}
7173

74+
@Restricted(NoExternalUse.class)
75+
public void setType(Type type) {
76+
type(type);
77+
}
78+
7279
@Override
7380
@NonNull
7481
public Iterable<SCMFile> children() throws IOException, InterruptedException {
@@ -101,6 +108,14 @@ protected SCMFile newChild(String name, boolean assumeIsDirectory) {
101108
return new BitbucketSCMFile(this, name, null, hash);
102109
}
103110

111+
@NonNull
112+
public BitbucketSCMFile child(@NonNull String path, @NonNull Type type) {
113+
BitbucketSCMFile scmFile = (BitbucketSCMFile) super.child(path);
114+
scmFile.type(type);
115+
scmFile.resolved = true;
116+
return scmFile;
117+
}
118+
104119
@Override
105120
@NonNull
106121
protected Type type() throws IOException, InterruptedException {

src/test/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ void test_SCMFile_does_not_contains_illegal_chars_in_the_name() throws Exception
7777
});
7878
}
7979

80+
@Issue("JENKINS-75208")
81+
@Test
82+
void test_SCMFile_when_client_return_path_attribute_with_folder_separator_on_cloud() throws Exception {
83+
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient("https://bitbucket.org");
84+
85+
BitbucketSCMFile root = new BitbucketSCMFile(client, "master", null);
86+
SCMFile file = root.child("folder/file.properties");
87+
String content = file.contentAsString();
88+
assertThat(content).isEqualTo("message=This is a test for metadata");
89+
}
90+
8091
@Issue("JENKINS-75157")
8192
@Test
8293
void test_SCMBinder_behavior_when_discover_the_Jenkinsfile_for_a_given_branch_on_cloud() throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message=This is a test for metadata
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"path": "folder/file.properties",
3+
"commit": {
4+
"hash": "e43fdffe2def75053da30efa8204d0317a0b932a",
5+
"links": {
6+
"self": {
7+
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/commit/e43fdffe2def75053da30efa8204d0317a0b932a"
8+
},
9+
"html": {
10+
"href": "https://bitbucket.org/amuniz/test-repos/commits/e43fdffe2def75053da30efa8204d0317a0b932a"
11+
}
12+
},
13+
"type": "commit"
14+
},
15+
"type": "commit_file",
16+
"attributes": [],
17+
"escaped_path": "folder/file.properties",
18+
"size": 35,
19+
"mimetype": null,
20+
"links": {
21+
"self": {
22+
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/src/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties"
23+
},
24+
"meta": {
25+
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/src/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties?format=meta"
26+
},
27+
"history": {
28+
"href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/filehistory/e43fdffe2def75053da30efa8204d0317a0b932a/folder/file.properties"
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)