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

Parameter is not interpreted in GIT Plugin - Branch Specifier

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • git-plugin
    • Git-Plugin: 4.2.2

    Description

      I have a pipeline with one branch to be build, it's a parameterized pipeline:

      Parameter BuildTag is not used by branch specifier.

      refs/tags/${BuildTag}

       

      hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/tags/${BuildTag}:refs/remotes/origin/${BuildTag}" returned status code 128:
      stdout: 
      stderr: fatal: Couldn't find remote ref refs/tags/${BuildTag}
      fatal: the remote end hung up unexpectedly	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2044)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:81)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:569)
      	at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:361)
      	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
      	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:115)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:69)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:427)
      Finished: FAILURE
      

      It worked with Git Plugin 4.1.1 and when I restore the plugin to this version it starts to work again!

      Regards Alex

      Attachments

        Issue Links

          Activity

            This happens because tags are now supported at https://github.com/jenkinsci/git-plugin/blob/git-4.2.1/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L262-L264. But when the GitSCMFileSystem is used, the branch specified is not expanded. If you remove that support, it works again.

            We can see that all those duplicates are about refs/tags and not refs/heads and the *lightweight checkout* (i.e. GitSCMFileSystem). If you try a parameterized refs/heads/ like for example refs/heads/$BRANCH you will notice that it does not work with either version 4.1.1 or 4.2.2.

            People are impact because now lightweight checkout supports tags, lightweight checkout is enabled by default, but the current implementation of the lightweight checkout does not expand variables.

            The workaround is to disable lightweight checkout if you use refs/tags.

            The fix is to support variable expansion of the branch specifier in GitSCMFileSystem.

            allan_burdajewicz Allan BURDAJEWICZ added a comment - This happens because tags are now supported at https://github.com/jenkinsci/git-plugin/blob/git-4.2.1/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L262-L264 . But when the GitSCMFileSystem is used, the branch specified is not expanded. If you remove that support, it works again. We can see that all those duplicates are about refs/tags and not refs/heads and the * lightweight checkout * (i.e. GitSCMFileSystem ). If you try a parameterized refs/heads/ like for example refs/heads/$BRANCH you will notice that it does not work with either version 4.1.1 or 4.2.2. People are impact because now lightweight checkout supports tags, lightweight checkout is enabled by default, but the current implementation of the lightweight checkout does not expand variables. The workaround is to disable lightweight checkout if you use refs/tags . The fix is to support variable expansion of the branch specifier in GitSCMFileSystem .

            This issue is actually blocked by JENKINS-48431 as this seems like a oversight inside the scm-api-plugin and workflow-cps-plugin

            jetersen Joseph Petersen added a comment - This issue is actually blocked by JENKINS-48431 as this seems like a oversight inside the scm-api-plugin and workflow-cps-plugin
            amidar Amit Dar added a comment -

            any chance this issue will be solved? the mess it causes is very painful....

            amidar Amit Dar added a comment - any chance this issue will be solved? the mess it causes is very painful....
            markewaite Mark Waite added a comment -

            amidar have you tried the workaround suggested by allan_burdajewicz?

            The workaround is to disable lightweight checkout if you use refs/tags.

            markewaite Mark Waite added a comment - amidar have you tried the workaround suggested by allan_burdajewicz ? The workaround is to disable lightweight checkout if you use refs/tags.
            amidar Amit Dar added a comment -

            markewaite, I have, but this doesn't accomplish what I want.

            I create a regular pipeline job, add a git parameter of "branch or tag" type, and then I want to use its contents as the content of the branch in the pipeline script section.

            the problem is that the parameter is not recognized at all during the pipeline script loading phase, only afterwards...

             

             

            amidar Amit Dar added a comment - markewaite , I have, but this doesn't accomplish what I want. I create a regular pipeline job, add a git parameter of "branch or tag" type, and then I want to use its contents as the content of the branch in the pipeline script section. the problem is that the parameter is not recognized at all during the pipeline script loading phase, only afterwards...    
            sso Simon So added a comment -

            amidar pretty sure you need to use `${branchOrTagName}` in the Branch Specifier

            sso Simon So added a comment - amidar pretty sure you need to use `${branchOrTagName}` in the Branch Specifier
            amidar Amit Dar added a comment -

            sso, I thought so too. I was wrong. the variable is not interpolated before the script is loaded, only afterwards.

            the only way I was able to do it was if I write the script itself in the job (and not use any SCM as the script source), but this is wrong in so many levels... so I added the comment to this issue instead

            Have you tried to do what you just offered? does it work for you? (maybe I'm doing something wrong... I hope I did....) 

            amidar Amit Dar added a comment - sso , I thought so too. I was wrong. the variable is not interpolated before the script is loaded, only afterwards. the only way I was able to do it was if I write the script itself in the job (and not use any SCM as the script source), but this is wrong in so many levels... so I added the comment to this issue instead Have you tried to do what you just offered? does it work for you? (maybe I'm doing something wrong... I hope I did....) 

            People

              Unassigned Unassigned
              alexz707 Alex Z
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: