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

Git plugin fails to replace parametrized value in scm checkout instead it is taking parameter variable as it is

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      In a pipeline job from a git repository where the "Branch Specifier" is given as a parameter and Lightweight option is also not checked but still I am getting below error

      hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune – origin +refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}" returned status code 128:
      stdout:
      stderr: fatal: Couldn't find remote ref refs/heads/${BRANCH}

      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2372)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1985)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:80)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:563)
      at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:348)
      at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
      at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
      at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:101)
      at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:82)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
      at hudson.security.ACL.impersonate(ACL.java:290)
      at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
      Finished: FAILURE

      I am trying with git parameter as well as string parameter and on both occasions getting same error

      I have observed the parameter value work well in fresstyle project but not work in simple pipeline job.

      I have tested with some git older version 3.0.0 which works will with pipeline job but same thing not works in later version

       

        Attachments

          Issue Links

            Activity

            Hide
            lucasheringer Lucas Heringer added a comment - - edited

            I have tested some Git plugin versions and found that this issue started with version 4.2.0

            Version 4.1.1 works fine but all versions starting with 4.2.0 and up will be affected by this issue.

            hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/tags/${VERSION}:refs/remotes/origin/${VERSION}" returned status code 128:
            stdout: 
            stderr: fatal: Couldn't find remote ref refs/tags/${VERSION}
            
            	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
            	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
            	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
            	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:573)
            	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:309)
            	at hudson.model.ResourceController.execute(ResourceController.java:97)
            	at hudson.model.Executor.run(Executor.java:428)
            Finished: FAILURE
            
            Show
            lucasheringer Lucas Heringer added a comment - - edited I have tested some Git plugin versions and found that this issue started with version 4.2.0 Version 4.1.1 works fine but all versions starting with 4.2.0 and up will be affected by this issue. hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/tags/${VERSION}:refs/remotes/origin/${VERSION}" returned status code 128: stdout: stderr: fatal: Couldn't find remote ref refs/tags/${VERSION} at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:573) 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:309) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:428) Finished: FAILURE
            Hide
            missedone nick tan added a comment -

            i have the same issue with Pipeline Job, i put environment variable in the "Branch Specifier" in the Pipeline Job config

            had quick go through the source code, looks like it's an issue on git fetch the specific branch spec.

            per the logs, i can see there are two steps on checking out the Jenkinsfile

            1. git checkout the branch
            2. git fetch the specific ref (not sure why need this step now that we have checkout the code at 1st step)

            it works at 1st step, because the Cli GitClient is instantiated with build specific environment: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L1239-L1240

            however, at 2nd step, when do the git fetch, the new GitClient doesn't the build context so it's instantiated with master env vars: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L308-L313

             

            I don't have the whole view to fix it, hope one of you folks can follow up.

            it'd be great if we can have dynamic branch for pipeline job

             

            Show
            missedone nick tan added a comment - i have the same issue with Pipeline Job, i put environment variable in the "Branch Specifier" in the Pipeline Job config had quick go through the source code, looks like it's an issue on git fetch the specific branch spec. per the logs, i can see there are two steps on checking out the Jenkinsfile git checkout the branch git fetch the specific ref (not sure why need this step now that we have checkout the code at 1st step) it works at 1st step, because the Cli GitClient is instantiated with build specific environment:  https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L1239-L1240 however, at 2nd step, when do the git fetch, the new GitClient doesn't the build context so it's instantiated with master env vars:  https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L308-L313   I don't have the whole view to fix it, hope one of you folks can follow up. it'd be great if we can have dynamic branch for pipeline job  
            Hide
            markewaite Mark Waite added a comment -

            Thanks for the investigation nick tan! I'm not sure that GitSCMFileSystem is intended to be used with varying refspecs, but your insights may help someone if they choose to investigate further if it would be possible to provide the job context to the GitSCMFileSystem that is used on the master to read the Jenkinsfile.

            Show
            markewaite Mark Waite added a comment - Thanks for the investigation nick tan ! I'm not sure that GitSCMFileSystem is intended to be used with varying refspecs, but your insights may help someone if they choose to investigate further if it would be possible to provide the job context to the GitSCMFileSystem that is used on the master to read the Jenkinsfile.
            Hide
            galindro Bruno Galindro da Costa added a comment - - edited

            I'm facing exactly the same issue with git plugin version 4.4.5. 

            Show
            galindro Bruno Galindro da Costa added a comment - - edited I'm facing exactly the same issue with git plugin version 4.4.5. 
            Hide
            rayvincent2 Ray Vincent added a comment -

            I've created a PR for this issue here: https://github.com/jenkinsci/git-plugin/pull/1040

            Can somebody please take a look and provide some feedback?

            Show
            rayvincent2 Ray Vincent added a comment - I've created a PR for this issue here: https://github.com/jenkinsci/git-plugin/pull/1040 Can somebody please take a look and provide some feedback?

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              mahan7 Mahantesh Hoolikatti
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated: