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

Refspec does not work for Multibranch Pipelines

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • None

      PS: Im not sure if it is only for Multibranch Pipelines, but thats my current workflow, and the only one Im aware of.

       

      Setting Refspec on the Configuration level:

       

      Making sure that the refspec is honored:

       

      But still when the branch runs, tags are fetched, but not the declared refspec:

       

       

      I believe this a regression, since this has worked for me in the past.

          [JENKINS-72731] Refspec does not work for Multibranch Pipelines

          Ruan created issue -

          Mark Waite added a comment - - edited

          I place the refspec configuration inside the Jenkinsfile rather than placing it on the multibranch Pipeline definition in my test jobs. The refspec inside the Jenkinsfile works as expected. Here are some examples of that configuration:

          I assume that "origin/develop" is a single branch on the remote repository. If it is a single branch, then I don't see how a multibranch Pipeline provides any benefit. It will find at most a single branch named "develop" and that single branch will result in a single job named "develop" in the multibranch Pipeline folder.

          If "origin/develop" is not a single branch on the remote repository, then I believe you need a different syntax to match all branches that are beneath the "develop" folder. The syntax for all branches in the develop folder is

          +refs/heads/develop/*:refs/remotes/origin/develop/*
          

          Mark Waite added a comment - - edited I place the refspec configuration inside the Jenkinsfile rather than placing it on the multibranch Pipeline definition in my test jobs. The refspec inside the Jenkinsfile works as expected. Here are some examples of that configuration: Multibranch Pipeline with JGit Multibranch Pipeline with command line git I assume that "origin/develop" is a single branch on the remote repository. If it is a single branch, then I don't see how a multibranch Pipeline provides any benefit. It will find at most a single branch named "develop" and that single branch will result in a single job named "develop" in the multibranch Pipeline folder. If "origin/develop" is not a single branch on the remote repository, then I believe you need a different syntax to match all branches that are beneath the "develop" folder. The syntax for all branches in the develop folder is +refs/heads/develop/*:refs/remotes/origin/develop/*
          Mark Waite made changes -
          Assignee Original: Mark Waite [ markewaite ]

          Ruan added a comment -

          Well, for a bit more context, I need Jenkins to be able to determine the commits between this branch (that is being built via the Multibranch Pipeline) and develop. I use this to parse Jira tickets from commit messages. 

           

          Thus, I need git to know about develop. This used to work before, but now there is no ref to develop. Ie the error in the last picture

          Ruan added a comment - Well, for a bit more context, I need Jenkins to be able to determine the commits between this branch (that is being built via the Multibranch Pipeline) and develop. I use this to parse Jira tickets from commit messages.    Thus, I need git to know about develop. This used to work before, but now there is no ref to develop. Ie the error in the last picture

          Mark Waite added a comment -

          I need Jenkins to be able to determine the commits between this branch (that is being built via the Multibranch Pipeline) and develop.

          You need a refspec that includes the branch you are building and the develop branch. The refspec you've defined does not include the branch you are building. The refspec definition can be multiple strings. Add a refspec definition (with a trailing '*') to match the branches you are building.

          I need git to know about develop. This used to work before, but now there is no ref to develop. Ie the error in the last picture

          That would have worked with that refspec in the past (by a happy accident) if you had not enabled the "honor refspec during clone" setting. In that case, the initial clone copied all the refspecs from the remote repository. The "honor refspec during clone" setting was added a while ago so that the initial clone did not make the mistake of always cloning all refspecs.

          Mark Waite added a comment - I need Jenkins to be able to determine the commits between this branch (that is being built via the Multibranch Pipeline) and develop. You need a refspec that includes the branch you are building and the develop branch. The refspec you've defined does not include the branch you are building. The refspec definition can be multiple strings. Add a refspec definition (with a trailing '*') to match the branches you are building. I need git to know about develop. This used to work before, but now there is no ref to develop. Ie the error in the last picture That would have worked with that refspec in the past (by a happy accident) if you had not enabled the "honor refspec during clone" setting. In that case, the initial clone copied all the refspecs from the remote repository. The "honor refspec during clone" setting was added a while ago so that the initial clone did not make the mistake of always cloning all refspecs.
          Mark Waite made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

          Ruan added a comment -

          Super, Ill give it a go and come back to this

          Ruan added a comment - Super, Ill give it a go and come back to this

          Ruan added a comment - - edited

          Actually, no luck. Seems like the honouring doesn't work for Multibranch pipelines as it should

          Previously, when this worked, my refspec was defined as:

          +refs/heads/develop:refs/remotes/origin/develop +refs/heads/master:refs/remotes/origin/master 

          This can be seen in the historical jobs that passed with this configuration (this is from the logs):

           > git fetch --no-tags --force --progress -- https://bitbucket.org/xxx/xxx.git +refs/heads/feat/playwright-e2e:refs/remotes/origin/feat/playwright-e2e +refs/heads/develop:refs/remotes/origin/develop +refs/heads/master:refs/remotes/origin/master # timeout=10

           

          But now

          My refspec is defined as (as per the comment above):

           

          +refs/heads/master:refs/remotes/origin/master +refs/heads/develop:refs/remotes/origin/develop +refs/heads/*:refs/remotes/@{remote}/* 

          This doesnt influence the fetch at all. Yes, I do have the honor ref spec checked.

          The fetch looks like this

          > git fetch --no-tags --force --progress – https://xxx@bitbucket.org/xxx/xxx.git +refs/heads/FixDeployment:refs/remotes/origin/FixDeployment # timeout=10 

          With Honor Refspec off

          This works as expected, as you mentioned, since it adds all branches.

          > git fetch --no-tags --force --progress -- git@bitbucket.org:xxx/xxx.git +refs/heads/*:refs/remotes/origin/* # timeout=10 

          This works for now, but this is not a long term solution. The refspec should work for multibranch pipelines like before

          Ruan added a comment - - edited Actually, no luck. Seems like the honouring doesn't work for Multibranch pipelines as it should Previously , when this worked, my refspec was defined as: +refs/heads/develop:refs/remotes/origin/develop +refs/heads/master:refs/remotes/origin/master This can be seen in the historical jobs that passed with this configuration (this is from the logs):  > git fetch --no-tags --force --progress -- https: //bitbucket.org/xxx/xxx.git +refs/heads/feat/playwright-e2e:refs/remotes/origin/feat/playwright-e2e +refs/heads/develop:refs/remotes/origin/develop +refs/heads/master:refs/remotes/origin/master # timeout=10   But now My refspec is defined as (as per the comment above):   +refs/heads/master:refs/remotes/origin/master +refs/heads/develop:refs/remotes/origin/develop +refs/heads/*:refs/remotes/@{remote}/* This doesnt influence the fetch at all. Yes, I do have the honor ref spec checked. The fetch looks like this > git fetch --no-tags --force --progress – https: //xxx@bitbucket.org/xxx/xxx.git +refs/heads/FixDeployment:refs/remotes/origin/FixDeployment # timeout=10 With Honor Refspec off This works as expected, as you mentioned, since it adds all branches. > git fetch --no-tags --force --progress -- git@bitbucket.org:xxx/xxx.git +refs/heads/*:refs/remotes/origin/* # timeout=10 This works for now, but this is not a long term solution. The refspec should work for multibranch pipelines like before
          Ruan made changes -
          Resolution Original: Not A Defect [ 7 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]
          Ruan made changes -
          Assignee New: Mark Waite [ markewaite ]

            Unassigned Unassigned
            rheynsza Ruan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: