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

New Jenkinsfiles can't be pushed to master on a plain Git server, but new branches work fine

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • Blue Ocean 1.3

      Summary:
      When connecting to a plain git repository over SSH, which has no Jenkinsfiles in it, attempts to save and create a Jenkinsfile to master will not write the Jenkinsfile. However, attempts to save to a new branch work fine.

      Prerequisites:

      • A remote git "server" you can successfully connect to via ssh.
      • A repository on same git server, which has been git init'd and has a README.md file on the master branch, but nothing else. The git history looks more or less like this:
        ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ git hist
        * 9d80d07 (HEAD -> master) yeah
        

      Steps to reproduce:
      1. Launch Blue Ocean and select New Pipeline.

      2. Select Git as your SCM, and provide a valid URL, in the form of ssh://username@1.2.3.4/path/to/git-server/repos/repo-name.

      3. When Blue Ocean presents you with an SSH key to register with the Git server, do so, by adding it to /home/username/.ssh/authorized_keys

      4. Click "Create Pipeline" and you'll be taken to the flow for creating your first Pipeline:

      5. Click "Create Pipeline," and create a very simple, one-stage Pipeline:

      6. Click "Save," provide a commit message, and leave the default setting of "Commit to master" selected. Then click Save & run.

      7. The progress bar near the top will move left-to-right as expected, but you'll be taken back to the "You don't have any branches that contain a Jenkinsfile" message:

      8. Check on the git server, to see if anything was created. Nothing was:

      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ git status
      On branch master
      nothing to commit, working directory clean
      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ ls
      README.md
      

      9. Repeat the process of creating a Pipeline. But this time, save it to a new branch, like so:

      10. This time, the Jenkinsfile has been created:

      11. And we can see this on the git server, too:

      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ git branch
        editor-created-this-branch
      * master
      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ git checkout editor-created-this-branch 
      Switched to branch 'editor-created-this-branch'
      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ ls
      Jenkinsfile  README.md
      ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ cat Jenkinsfile 
      pipeline {
        agent any
        stages {
          stage('Second Attempt') {
            steps {
              echo 'Hello from editor-created-this-branch'
            }
          }
        }
      }ubuntu@ip-172-18-40-84:~/git-server/repos/per-stage-editing$ 
      

          [JENKINS-46885] New Jenkinsfiles can't be pushed to master on a plain Git server, but new branches work fine

          Keith Zantow added a comment -

          Note: the crux of the problem is that this isn't using a bare repository. But it needs better error reporting and to be able to handle actual empty repositories. I'll fix those as part of this ticket.

          Keith Zantow added a comment - Note: the crux of the problem is that this isn't using a bare repository. But it needs better error reporting and to be able to handle actual empty repositories. I'll fix those as part of this ticket.

          Keith Zantow added a comment -

          kshultz just to reiterate: the reason you could not save to master was because you were using a non-bare git repository.

          Keith Zantow added a comment - kshultz just to reiterate: the reason you could not save to master was because you were using a non-bare git repository .

          Keith Zantow added a comment -

          Provided improved error messaging during failures and fixed the case saving to a repository with no commits (e.g. go to Github, click create repo, then in Jenkins try to add it and use the editor to create a Jenkinsfile for the first commit)

          Keith Zantow added a comment - Provided improved error messaging during failures and fixed the case saving to a repository with no commits (e.g. go to Github, click create repo, then in Jenkins try to add it and use the editor to create a Jenkinsfile for the first commit)

          Karl Shultz added a comment -

          Testing Notes:

          Karl Shultz added a comment - Testing Notes: This can be tested by using an existing automated test , and pointing live.properties to a non-bare Git ssh repo.

            kzantow Keith Zantow
            kshultz Karl Shultz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: