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

Cannot use ENV variable for repository url in Git Publisher

      If you've a variable as the Repository URL, e.g. ${GIT_REPO}

      {GIT_REPO}

      doesn't get replaced in git publisher - it will do

      hudson.plugins.git.GitException: Command "git push ${GIT_REPO} 1.1.761 -f" returned status code 128:
      stdout:

          [JENKINS-27508] Cannot use ENV variable for repository url in Git Publisher

          Deniz Bahadir added a comment -

          There are also other form-fields where successfull variable-substitution would make sense.

          For example I stumbled about the missing substitution-feature for the Path field of the Sparse Checkout path option.
          However, variable-substitution works e.g. for the Local subdirectory for repo field of the Check out to a sub-directory option.

          I would suggest this plugin supports (environment) variable-substitution in all form-fields.

          Deniz Bahadir added a comment - There are also other form-fields where successfull variable-substitution would make sense. For example I stumbled about the missing substitution-feature for the Path field of the Sparse Checkout path option. However, variable-substitution works e.g. for the Local subdirectory for repo field of the Check out to a sub-directory option. I would suggest this plugin supports (environment) variable-substitution in all form-fields.

          Monkey Little added a comment - - edited

          As of June 30, 2017, repo path and branch spec can use variables and they are expanded.  But the sparse checkout path is still not.

          Monkey Little added a comment - - edited As of June 30, 2017, repo path and branch spec can use variables and they are expanded.  But the sparse checkout path is still not.

          believe I see a related issue when used with a pipeline. In this case I have a parameterized build, I use the parameter for the branch name but it doesn't get expanded.  If I do the same think in a freestyle job it works.

          Daniel Carreira added a comment - believe I see a related issue when used with a pipeline. In this case I have a parameterized build, I use the parameter for the branch name but it doesn't get expanded.  If I do the same think in a freestyle job it works.

          dcarreira your problem sounds like the groovy didn't properly interpret the string; is it double quoted?

          Aaron D. Marasco added a comment - dcarreira your problem sounds like the groovy didn't properly interpret the string; is it double quoted?

          Below is the console log from the job.

          MY_BRANCH is a string parameter (I've also tried it as a branch parameter with the same results).

          I then try to use the variable via the git plug-in in a Pipeline script in SCM job. (I just tried adding double quotes around the ${MY_BRANCH} same results except the log show the double quotes.

           

           

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

          at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1996)
          at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1715)
          at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72)
          at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:405)
          at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:351)
          at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:196)
          at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:172)
          at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:99)
          at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59)
          at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:263)
          at hudson.model.ResourceController.execute(ResourceController.java:97)
          at hudson.model.Executor.run(Executor.java:421)
          Finished: FAILURE

          Daniel Carreira added a comment - Below is the console log from the job. MY_BRANCH is a string parameter (I've also tried it as a branch parameter with the same results). I then try to use the variable via the git plug-in in a Pipeline script in SCM job. (I just tried adding double quotes around the ${MY_BRANCH} same results except the log show the double quotes.     hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress origin +refs/heads/${MY_BRANCH}:refs/remotes/origin/${MY_BRANCH} --prune" returned status code 128: stdout: stderr: fatal: Couldn't find remote ref refs/heads/${MY_BRANCH} at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1996) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1715) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:405) at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:351) at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:196) at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:172) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:99) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:263) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:421) Finished: FAILURE

          dcarreira sorry, I meant in the groovy code, assuming MY_BRANCH was an input; otherwise, yeah, this sounds like the same problem since it's at the UI-level.

          Aaron D. Marasco added a comment - dcarreira sorry, I meant in the groovy code, assuming MY_BRANCH was an input; otherwise, yeah, this sounds like the same problem since it's at the UI-level.

          Is there an ETA on the fix? Thanks in advance.

          Daniel Carreira added a comment - Is there an ETA on the fix? Thanks in advance.

          jlpinardon added a comment - - edited

          I confirm that this problem is realy annoying !
          I'd like to use a build parameter named branchName as the name of the branch from which the pipeline script is extracted.

          I tried this :

          • with and without quotes
          • with branchName defined as a build parameter
          • with branchName defined in the prepare an environment for the rnu
          • with branchName defined as a global environment variable

          In each and every cases, the result is exactly the same. The exact term "${branchName}" is used rather than the value :

          [BFA] Done. 0s
          hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/"${branchName}":refs/remotes/origin/"${branchName}" --prune" returned status code 128:
          {{stdout: }}
          stderr: fatal: Couldn't find remote ref refs/heads/"${branchName}"

           Note that the quite complete help associated with the field states that an environment variable can be used !

          This is really annoying and this does not help for pipeline adoption. Besides, this bug is classified as critical, so could we have an idea of a date for its resolution ?

          jlpinardon added a comment - - edited I confirm that this problem is realy annoying ! I'd like to use a build parameter named branchName as the name of the branch from which the pipeline script is extracted. I tried this : with and without quotes with branchName defined as a build parameter with branchName defined in the prepare an environment for the rnu with branchName defined as a global environment variable In each and every cases, the result is exactly the same. The exact term "${branchName}" is used rather than the value : [BFA] Done. 0s hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/"${branchName}":refs/remotes/origin/"${branchName}" --prune" returned status code 128: {{stdout: }} stderr: fatal: Couldn't find remote ref refs/heads/"${branchName}"  Note that the quite complete help associated with the field states that an environment variable can be used ! This is really annoying and this does not help for pipeline adoption . Besides, this bug is classified as critical , so could we have an idea of a date for its resolution ?

          Maciej Kubiak added a comment -

          The workaround I've discovered is to disable lightweight checkout. Then the envionment variable is correctly picked-up without any need for quotes

          Maciej Kubiak added a comment - The workaround I've discovered is to disable lightweight checkout. Then the envionment variable is correctly picked-up without any need for quotes

          Mark Waite added a comment - - edited

          This issue report is specifically about the git publisher within the git plugin. The git publisher is not available in Pipeline. The git publisher is available in Freestyle jobs.

          • qbix, lightweight checkout is not available in Freestyle jobs
          • jlpinardon git publisher does not perform a fetch and does not work with Pipelines
          • dcarreira git publisher does not work with Pipelines

          I'm unable to duplicate the issue as described. Steps I took while trying to duplicate the issue:

          1. Create a Freestyle job with a parameter, REPO_URL_FRAGMENT with choices MarkEWaite/jenkins-bugs, MarkEWaite/git-client-plugin, MarkEWaite/git-plugin, and MarkEWaite/platformlabeler-plugin
          2. Use git as the SCM in that Freestyle job from repository https://github.com//${REPO_URL}
          3. Checkout the master branch in that Freestyle job
          4. Enable the "Merge before build" git plugin extension with repository origin, branch master, and default settings for merge strategy and fast forward mode
          5. Add a conditional step to the Freestyle job that runs ant increment if the file build.xml is found in the workspace
          6. Enable Git Publisher as a Post-build Action, configured to push only if the build succeeds, merge the result to the branch master with remote named origin

          When I perform those steps, the job runs successfully.

          If I choose the REPO_URL_FRAGMENT value as MarkEWaite/jenkins-bugs, the job runs successfully, increments a build number, and pushes the change to the master branch of my jenkins-bugs repository.

          If I choose the REPO_URL_FRAGMENT value as something other than MarkEWaite/jenkins-bugs, the job runs successfully, does not increment a build number, and does not push anything to the master branch of the selected repository.

          See my job definition for the precise details JENKINS-27508-config.xml

          Mark Waite added a comment - - edited This issue report is specifically about the git publisher within the git plugin. The git publisher is not available in Pipeline. The git publisher is available in Freestyle jobs. qbix , lightweight checkout is not available in Freestyle jobs jlpinardon git publisher does not perform a fetch and does not work with Pipelines dcarreira git publisher does not work with Pipelines I'm unable to duplicate the issue as described. Steps I took while trying to duplicate the issue: Create a Freestyle job with a parameter, REPO_URL_FRAGMENT with choices MarkEWaite/jenkins-bugs, MarkEWaite/git-client-plugin, MarkEWaite/git-plugin, and MarkEWaite/platformlabeler-plugin Use git as the SCM in that Freestyle job from repository https://github.com//$ {REPO_URL } Checkout the master branch in that Freestyle job Enable the "Merge before build" git plugin extension with repository origin , branch master , and default settings for merge strategy and fast forward mode Add a conditional step to the Freestyle job that runs ant increment if the file build.xml is found in the workspace Enable Git Publisher as a Post-build Action, configured to push only if the build succeeds, merge the result to the branch master with remote named origin When I perform those steps, the job runs successfully. If I choose the REPO_URL_FRAGMENT value as MarkEWaite/jenkins-bugs , the job runs successfully, increments a build number, and pushes the change to the master branch of my jenkins-bugs repository. If I choose the REPO_URL_FRAGMENT value as something other than MarkEWaite/jenkins-bugs , the job runs successfully, does not increment a build number, and does not push anything to the master branch of the selected repository. See my job definition for the precise details JENKINS-27508-config.xml

            yashj21 Yash Amrut Jain
            peterlai Peter lai
            Votes:
            6 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: