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

ENV VAR / Job Parameter not being used in Git Checkout

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical
    • git-plugin
    • None

      I have a job with a String Parameter - BRANCH_NAME

      I am running' Pipeline Script from SCM'

      I have specified the parameter BRANCH_NAME in the 'Branches to Build' field as an environment variable (i,e ${BRANCH_NAME})

      It does not clone that branch - I get an error:
      hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune – origin +refs/heads/${BRANCH_NAME}:refs/remotes/origin/${BRANCH_NAME}"

       

          [JENKINS-63457] ENV VAR / Job Parameter not being used in Git Checkout

          Daniel Laird added a comment -

          Forgot to add we are running 4.2.1 of the plugin 

          Daniel Laird added a comment - Forgot to add we are running 4.2.1 of the plugin 

          Mark Waite added a comment - - edited

          Please provide your pipeline definition file, especially the checkout step. I suspect that you've used single quotes around the refspec instead of using double quotes. It may also be that you need to use ${env.BRANCH_NAME} in the step rather than ${BRANCH_NAME}.

          Mark Waite added a comment - - edited Please provide your pipeline definition file, especially the checkout step. I suspect that you've used single quotes around the refspec instead of using double quotes. It may also be that you need to use ${env.BRANCH_NAME } in the step rather than ${BRANCH_NAME }.

          Daniel Laird added a comment -

          Hi - Its a manually configured 'Pipeline' Job - which I have a string parameter:

          I then specify is a Pipeline from SCM
          And select the following:

          It never gets to the point where it runs the pipeline script within SCM.  It seems to not checkout the specified branch (if i use a hardcoded value it works)

          Does that help?

           

          Daniel Laird added a comment - Hi - Its a manually configured 'Pipeline' Job - which I have a string parameter: I then specify is a Pipeline from SCM And select the following: It never gets to the point where it runs the pipeline script within SCM.  It seems to not checkout the specified branch (if i use a hardcoded value it works) Does that help?  

          Daniel Laird added a comment - - edited

          I also tried a 'Git Parameter' and not a 'String Parameter' - it lists the branches succesfully but still cant be used as an ENV var in the Branch Specifier field.

          Daniel Laird added a comment - - edited I also tried a 'Git Parameter' and not a 'String Parameter' - it lists the branches succesfully but still cant be used as an ENV var in the Branch Specifier field.

          Mark Waite added a comment - - edited

          Duplicate of JENKINS-49758.

          I believe this use case is much better handled by using a multibranch pipeline to automatically create and delete a job for each branch rather than having a single job which can switch from one branch to another branch based on a parameter from the user.

          Mark Waite added a comment - - edited Duplicate of JENKINS-49758 . I believe this use case is much better handled by using a multibranch pipeline to automatically create and delete a job for each branch rather than having a single job which can switch from one branch to another branch based on a parameter from the user.

            markewaite Mark Waite
            djl197 Daniel Laird
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: