Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71363

Streaming support (getRawFileStream) causes RequestRejectedException in Bitbucket (500)

    • 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) 

          [JENKINS-71363] Streaming support (getRawFileStream) causes RequestRejectedException in Bitbucket (500)

          Jan added a comment - - edited

          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:

          public InputStream getRawFileStream(BitbucketSCMFile scmFile) {
              HttpUrl.Builder urlBuilder = bitbucketRequestExecutor.getCoreRestPath().newBuilder()
                      .addPathSegment("projects")
                      .addPathSegment(projectKey)
                      .addPathSegment("repos")
                      .addPathSegment(repositorySlug)
                      .addPathSegment("raw")
                      .addPathSegment(scmFile.getFilePath());
              scmFile.getRef().map(ref -> urlBuilder.addQueryParameter("at", ref));
              HttpUrl url = urlBuilder.build();
          
              return bitbucketRequestExecutor.makeStreamingGetRequest(url);
          } 

          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:

          @Override
          public InputStream getRawFileStream(BitbucketSCMFile scmFile) {
              HttpUrl.Builder urlBuilder = bitbucketRequestExecutor.getCoreRestPath().newBuilder()
                      .addPathSegment("projects")
                      .addPathSegment(projectKey)
                      .addPathSegment("repos")
                      .addPathSegment(repositorySlug)
                      .addPathSegment("raw")
                      .addPathSegments(scmFile.getFilePath());
              scmFile.getRef().map(ref -> urlBuilder.addQueryParameter("at", ref));
              HttpUrl url = urlBuilder.build();
          
              return bitbucketRequestExecutor.makeStreamingGetRequest(url);
          }

           

          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.

          Jan added a comment - - edited 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 : public InputStream getRawFileStream(BitbucketSCMFile scmFile) { HttpUrl.Builder urlBuilder = bitbucketRequestExecutor.getCoreRestPath().newBuilder() .addPathSegment( "projects" ) .addPathSegment(projectKey) .addPathSegment( "repos" ) .addPathSegment(repositorySlug) .addPathSegment( "raw" ) .addPathSegment(scmFile.getFilePath()); scmFile.getRef().map(ref -> urlBuilder.addQueryParameter( "at" , ref)); HttpUrl url = urlBuilder.build(); return bitbucketRequestExecutor.makeStreamingGetRequest(url); } The scmFile.getFilePath() should be added via " addPathSegment s " (note the additional "s") instead, as is done in other places. Thus, the fixed code would be: @Override public InputStream getRawFileStream(BitbucketSCMFile scmFile) { HttpUrl.Builder urlBuilder = bitbucketRequestExecutor.getCoreRestPath().newBuilder() .addPathSegment( "projects" ) .addPathSegment(projectKey) .addPathSegment( "repos" ) .addPathSegment(repositorySlug) .addPathSegment( "raw" ) .addPathSegments(scmFile.getFilePath()); scmFile.getRef().map(ref -> urlBuilder.addQueryParameter( "at" , ref)); HttpUrl url = urlBuilder.build(); return bitbucketRequestExecutor.makeStreamingGetRequest(url); }   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.

          Garen Parham added a comment -

          We also ran into this issue yesterday after upgrading to the 3.4.1 version of the plugin.   We see it when using the following versions:

          • Jenkins 2.375.4
          • Bitbucket Server v7.17.15 (LTS)
          • atlassian-bitbucket-server-integration (plugin) 3.4.1

          Reverting to the older 3.3.2 version of the plugin resolved the issue for us.

          Appears to be caused by PR 378 to address JENKINS-66829.

          Garen Parham added a comment - We also ran into this issue yesterday after upgrading to the 3.4.1 version of the plugin.   We see it when using the following versions: Jenkins 2.375.4 Bitbucket Server v7.17.15 (LTS) atlassian-bitbucket-server-integration (plugin) 3.4.1 Reverting to the older 3.3.2 version of the plugin resolved the issue for us. Appears to be caused by PR 378 to address JENKINS-66829 .

          Viktor Sam added a comment -

          Also has same issue:

          • Jenkins 2.407
          • Bitbucket Server v7.5.2
          • atlassian-bitbucket-server-integration (plugin) 3.4.1

          Fixed by revert back to 3.3.2 plugin version

          Viktor Sam added a comment - Also has same issue: Jenkins 2.407 Bitbucket Server v7.5.2 atlassian-bitbucket-server-integration (plugin) 3.4.1 Fixed by revert back to 3.3.2 plugin version

            Unassigned Unassigned
            denvit_scs Denys
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: