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

Adding Bitbucket server with http instead of https URL breaks Creation flow

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • Jenkins:
      Core: 2.89
      Plugins: latest on experimental update center, including Blue Ocean 1.3.2
      bitbucket-branch-source 2.2.7

      Client:
      Fedora Workstation 26
      Chrome 62.0.3202.89

      SCM:
      Bitbucket Server 5.2.3
    • Pipeline - December

      Summary:
      After successfully connecting to a repo on a Bitbucket server which has code, but does not have a Jenkinsfile in it, attempting to create one fails in Blue Ocean. The only error message shown is the word "Found" in red text. This is caused by setting up the Bitbucket server with an HTTP URL, rather than an HTTPS URL. Changing from HTTP to HTTPS resolves the issue.

      Routing:
      It's unclear to me at the moment if this is an issue in bitbucket-branch-source, in BO itself, in the editor, or somewhere else.

      Steps to recreate:
      1. Make a local clone of the simple-maven-project-with-tests repo found here.

      2. On your Bitbucket server, create a repository, which you'll use as a remote for this repo you just cloned:

      3. Using Blue Ocean, connect to this Bitbucket server by providing your credentials. Shown below, I've gotten as far as having found the repo, but have not yet selected it:

      4. Click "Create Pipeline." You'll be told there are no Jenkinsfiles, which is expected.

      5. Click the second "Create Pipeline" button which was just generated, and you'll be taken to the editor:

      6. Leave Agent set to any (the default), and click the button to create a stage. Add a Shell Script step, and enter mvn -X clean package as the step:

      7. Click Save, enter a commit message, and leave the default setting of Commit to master. Click Save and Run, and notice the Error at the top of this same dialog:

      8. This can also be recreated by using a different branch name than master.

      Why this is a problem:

      • I've been given no direction as far as what has gone wrong.
      • There's nothing at all in the Jenkins log

      Later this evening, I'll capture a HAR file while retracing my steps.

        1. 172.18.40.95.har
          1.59 MB
        2. image-2017-11-13-17-36-29-175.png
          image-2017-11-13-17-36-29-175.png
          376 kB
        3. image-2017-11-13-17-38-30-222.png
          image-2017-11-13-17-38-30-222.png
          306 kB
        4. image-2017-11-13-17-39-14-912.png
          image-2017-11-13-17-39-14-912.png
          323 kB
        5. image-2017-11-13-17-39-47-604.png
          image-2017-11-13-17-39-47-604.png
          298 kB
        6. image-2017-11-13-17-42-01-061.png
          image-2017-11-13-17-42-01-061.png
          311 kB
        7. image-2017-11-13-17-44-04-291.png
          image-2017-11-13-17-44-04-291.png
          352 kB
        8. screenshot-1.png
          screenshot-1.png
          427 kB
        9. screenshot-2.png
          screenshot-2.png
          400 kB
        10. screenshot-3.png
          screenshot-3.png
          400 kB
        11. screenshot-4.png
          screenshot-4.png
          569 kB
        12. screenshot-5.png
          screenshot-5.png
          361 kB
        13. screenshot-6.png
          screenshot-6.png
          354 kB

          [JENKINS-47984] Adding Bitbucket server with http instead of https URL breaks Creation flow

          Vivek Pandey added a comment -

          kshultz Ah, problem found. Issue is really that bitbucket server is setup with https and it wants us to use https one. When you give http://bitbucket.beescloud.com as bb server endpoint url we check if its valid url and save this URL. Later on when pipeline editor tries to save Jenkinsfile, bb server api returns 302 that it fails to handle.

          I think the fix is simply to handle 302. Please note this has nothing to do with bitbucket-branch-source latest version. This bug exists in all versions of blueocean. Its minor in nature as workaround is or perhaps right way is for users to setup bb server using https url.

          To understand whats going on see the following call below sends 302 with location header pointing to correct https based url.

          $ curl -v  -H 'accept: application/json'  "http:///bitbucket.beescloud.com/" 
          * Unwillingly accepted illegal URL using 3 slashes!
          *   Trying 52.22.14.249...
          * TCP_NODELAY set
          * Connected to bitbucket.beescloud.com (52.22.14.249) port 80 (#0)
          > GET / HTTP/1.1
          > Host: bitbucket.beescloud.com
          > User-Agent: curl/7.54.0
          > accept: application/json
          > 
          < HTTP/1.1 302 Found
          < Cache-Control: no-cache
          < Content-length: 0
          < Location: https://bitbucket.beescloud.com/
          < Connection: close
          < 
          * Closing connection 0
          

          Vivek Pandey added a comment - kshultz Ah, problem found. Issue is really that bitbucket server is setup with https and it wants us to use https one. When you give http://bitbucket.beescloud.com as bb server endpoint url we check if its valid url and save this URL. Later on when pipeline editor tries to save Jenkinsfile, bb server api returns 302 that it fails to handle. I think the fix is simply to handle 302. Please note this has nothing to do with bitbucket-branch-source latest version. This bug exists in all versions of blueocean . Its minor in nature as workaround is or perhaps right way is for users to setup bb server using https url. To understand whats going on see the following call below sends 302 with location header pointing to correct https based url. $ curl -v -H 'accept: application/json' "http: ///bitbucket.beescloud.com/" * Unwillingly accepted illegal URL using 3 slashes! * Trying 52.22.14.249... * TCP_NODELAY set * Connected to bitbucket.beescloud.com (52.22.14.249) port 80 (#0) > GET / HTTP/1.1 > Host: bitbucket.beescloud.com > User-Agent: curl/7.54.0 > accept: application/json > < HTTP/1.1 302 Found < Cache-Control: no-cache < Content-length: 0 < Location: https: //bitbucket.beescloud.com/ < Connection: close < * Closing connection 0

          Karl Shultz added a comment - - edited

          The entire flow works fine when connecting to a local Bitbucket instance running from the Atlassian SDK. I connected using an http URL as requested, and created this with the editor:

          Granted, this isn't the same Jenkins instance as I was originally using. But the plugin levels should be the same, since they're all coming from the experimental UC. BBBS is 2.2.7 on both.

          Karl Shultz added a comment - - edited The entire flow works fine when connecting to a local Bitbucket instance running from the Atlassian SDK. I connected using an http URL as requested, and created this with the editor: Granted, this isn't the same Jenkins instance as I was originally using. But the plugin levels should be the same, since they're all coming from the experimental UC. BBBS is 2.2.7 on both.

          Karl Shultz added a comment -

          Heh, great minds. I confirmed in my comment this morning that this has nothing to do with 2.2.7. I recreated it with 2.2.5. Didn't bother to go back any farther than that.

          Handling the 302 sounds like a fine way to go about it. Entering http instead of https is a mistake which is pretty easy to make. Some sort of guidance for users who do this would be a nice usability enhancement.

          Karl Shultz added a comment - Heh, great minds. I confirmed in my comment this morning that this has nothing to do with 2.2.7. I recreated it with 2.2.5. Didn't bother to go back any farther than that. Handling the 302 sounds like a fine way to go about it. Entering http instead of https is a mistake which is pretty easy to make. Some sort of guidance for users who do this would be a nice usability enhancement.

          Michael Neale added a comment -

          actually for 302 and APIs, I don't think they should be automatically followed/handled. telling the user to use the correct URL is the way. Generally with APIs it is a no no to automatically follow redirect requests less the credentials get sent to the wrong place (that is my understanding at least, as to why most libraries won't do it for you). 

          Michael Neale added a comment - actually for 302 and APIs, I don't think they should be automatically followed/handled. telling the user to use the correct URL is the way. Generally with APIs it is a no no to automatically follow redirect requests less the credentials get sent to the wrong place (that is my understanding at least, as to why most libraries won't do it for you). 

          Vivek Pandey added a comment -

          michaelneale I am not sure about that. Generally such policies are applied at API endpoint not client. For example GitHub API suggests clients to handle 302 by retrying with the url in Location header. https://developer.github.com/v3/#http-redirects. Basically if API endpoint is telling client to follow at a different url client should do it. Same goes for AWS S3, http://docs.aws.amazon.com/AmazonS3/latest/dev/Redirects.html.

          Vivek Pandey added a comment - michaelneale I am not sure about that. Generally such policies are applied at API endpoint not client. For example GitHub API suggests clients to handle 302 by retrying with the url in Location header. https://developer.github.com/v3/#http-redirects . Basically if API endpoint is telling client to follow at a different url client should do it. Same goes for AWS S3, http://docs.aws.amazon.com/AmazonS3/latest/dev/Redirects.html .

          Michael Neale added a comment -

          vivek ok in that case I revoke my statement, yes should be honoured. The fact that github say this implies they would likely change their mind and move apis around, so should follow it (I guess Bitbucket would have same policy). Good digging 

          Michael Neale added a comment - vivek ok in that case I revoke my statement, yes should be honoured. The fact that github say this implies they would likely change their mind and move apis around, so should follow it (I guess Bitbucket would have same policy). Good digging 

          Vivek Pandey added a comment -

          michaelnealekshultz bitbucket API docs do not talk about handling of 302. So I talked to Bitbucket guys about it. They suggested disabling auto-redirect. I think its best we report error and tell users that bitbucket is suggesting a different URL to be used and users should use that instead.

          Vivek Pandey added a comment - michaelneale kshultz bitbucket API docs do not talk about handling of 302. So I talked to Bitbucket guys about it. They suggested disabling auto-redirect. I think its best we report error and tell users that bitbucket is suggesting a different URL to be used and users should use that instead.

          Vivek Pandey added a comment -

          Reduced scope to Minor as using incorrect URL (http instead of https if bb server is running behind https) is expected to fail during creation flow. The fix is going to be fail early/fast instead of at the very end when Jenkinsfile is saved.

          Vivek Pandey added a comment - Reduced scope to Minor as using incorrect URL (http instead of https if bb server is running behind https) is expected to fail during creation flow. The fix is going to be fail early/fast instead of at the very end when Jenkinsfile is saved.

          Vivek Pandey added a comment -

          Vivek Pandey added a comment - PR opened: https://github.com/jenkinsci/blueocean-plugin/pull/1558

          Karl Shultz added a comment -

          Testing Notes:

          • A test is already part of the PR.

          Karl Shultz added a comment - Testing Notes: A test is already part of the PR .

            vivek Vivek Pandey
            kshultz Karl Shultz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: