-
Bug
-
Resolution: Fixed
-
Major
-
atlassian-bitbucket-server-integration-plugin/3.4.1
Jenkins/2.387.1
-
-
3.4.2
After this commit, the requests to our Bitbucket Server instance (v7.21.6) started failing:
bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/k8s/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.3.2 200 /rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/k8s/Jenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.4.1 500 /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2FJenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.4.1 500 /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2FJenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.4.1 500 /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2FJenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1 bitbucket-jenkins-integration/3.4.1 500 /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2Fk8s%2FJenkinsfile?at=refs%2Fheads%2Fdevelop HTTP/1.1
The problem seems to be the following:
- Our Jenkinsfile is not in the root directory
- atlassian-bitbucket-server-integration-plugin is using the newest version 3.4.1
- atlassian-bitbucket-server-integration-plugin 3.4.1 is encoding the file path
Thus, the commit above seems to have introduced a regression: the file path is now encoded:
/rest/api/1.0/projects/XYZ/repos/masked/browse/cicd/Jenkinsfile?at=refs%2Fheads%2Fdevelop (3.3.2) becomes /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2Fk8s%2FJenkinsfile?at=refs%2Fheads%2Fdevelop (3.4.1)
This in turn causes the following error in Bitbucket:
org.springframework.security.web.firewall.RequestRejectedException: The requestURI cannot contain encoded slash. Got /rest/api/1.0/projects/XYZ/repos/masked/raw/cicd%2FJenkinsfile
and the following error in the Jenkins plugin:
com.atlassian.bitbucket.jenkins.internal.client.exception.ServerErrorException: - response: 500 at com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.handleError(HttpRequestExecutorImpl.java:151) at com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.makeRequest(HttpRequestExecutorImpl.java:95) at com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.performStreamingGet(HttpRequestExecutorImpl.java:174) at com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.executeStreamingGet(HttpRequestExecutorImpl.java:66) at com.atlassian.bitbucket.jenkins.internal.client.BitbucketRequestExecutor.streamGetRequest(BitbucketRequestExecutor.java:195) at com.atlassian.bitbucket.jenkins.internal.client.BitbucketRequestExecutor.makeStreamingGetRequest(BitbucketRequestExecutor.java:117) at com.atlassian.bitbucket.jenkins.internal.client.BitbucketFilePathClientImpl.getRawFileStream(BitbucketFilePathClientImpl.java:64) at com.atlassian.bitbucket.jenkins.internal.scm.filesystem.BitbucketSCMFile.content(BitbucketSCMFile.java:81) at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:335) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:108) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:312) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:442)
Just wanted to comment that I have the same problem, only that I get a 400 error because the request is malformed, and the Bitbucket server instance (in this case, version 7.21.11) chooses to return said code.
The root cause is the following method in com.atlassian.bitbucket.jenkins.internal.client.BitbucketFilePathClientImpl#getRawFileStream:
The scmFile.getFilePath() should be added via "addPathSegments" (note the additional "s") instead, as is done in other places. Thus, the fixed code would be:
On another note, It would be nice if the requests and responses could be logged at debug level so that one can identify the problem in cases where SCM server logs are not available and you only have access to Jenkins. Otherwise, only the status code is getting printed and you have no clue what has happened.