Skip to content

Commit e1da70c

Browse files
authored
[JENKINS-75208] Checkout on bitbucket server fail with IllegalArgumentException "Name cannot contain '/'" (#981)
Fix the file name that the BitbucketServerAPIClient return from getFile method. Before was used the href instead of the name
1 parent 109453d commit e1da70c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ public SCMFile getFile(@NonNull BitbucketSCMFile file) throws IOException, Inter
10831083
} catch (FileNotFoundException e) {
10841084
type = Type.NONEXISTENT;
10851085
}
1086-
return new BitbucketSCMFile((BitbucketSCMFile) file.parent(), file.getRef(), type, file.getHash());
1086+
return new BitbucketSCMFile((BitbucketSCMFile) file.parent(), file.getName(), type, file.getHash());
10871087
}
10881088

10891089
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import static org.assertj.core.api.Assertions.assertThat;
3838
import static org.assertj.core.api.Assertions.assertThatThrownBy;
39+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3940

4041
@WithJenkins
4142
class BitbucketSCMFileTest {
@@ -53,11 +54,29 @@ static void init(JenkinsRule rule) {
5354
void verify_content_throws_FileNotFoundException_when_file_does_not_exists() {
5455
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient("https://acme.bitbucket.com");
5556

56-
BitbucketSCMFile parent = new BitbucketSCMFile(client, "master", "hash");
57+
BitbucketSCMFile parent = new BitbucketSCMFile(client, "master", "51af66dad14c38d7c69874c57a65f77f688e3f33");
5758
BitbucketSCMFile file = new BitbucketSCMFile(parent, "pipeline_config.groovy", Type.REGULAR_FILE, "046d9a3c1532acf4cf08fe93235c00e4d673c1d2");
5859
assertThatThrownBy(file::content).isInstanceOf(FileNotFoundException.class);
5960
}
6061

62+
@Issue("JENKINS-75208")
63+
@Test
64+
void test_SCMFile_does_not_contains_illegal_chars_in_the_name() throws Exception {
65+
BitbucketApi client = BitbucketIntegrationClientFactory.getApiMockClient("https://acme.bitbucket.com");
66+
67+
BitbucketSCMFile parent = new BitbucketSCMFile(client, "feature/pipeline", null);
68+
BitbucketSCMFile file = new BitbucketSCMFile(parent, "Jenkinsfile", null, "2c130d767a38ac4ef511797f221315f35a2aea55");
69+
SCMFile scmFile = assertDoesNotThrow(() -> client.getFile(file));
70+
71+
assertThat(scmFile.isFile()).isTrue();
72+
assertThat(scmFile.getName()).isEqualTo("Jenkinsfile");
73+
assertThat(scmFile).isInstanceOfSatisfying(BitbucketSCMFile.class,
74+
f -> {
75+
assertThat(f.getRef()).isEqualTo("feature/pipeline");
76+
assertThat(f.getHash()).isEqualTo("2c130d767a38ac4ef511797f221315f35a2aea55");
77+
});
78+
}
79+
6180
@Issue("JENKINS-75157")
6281
@Test
6382
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,3 @@
1+
{
2+
"type": "FILE"
3+
}

0 commit comments

Comments
 (0)