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

Pipeline script from SCM does not expand build parameters/env variables for lightweight checkouts

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: scm-api-plugin
    • Labels:
      None
    • Environment:
      Jenkins LTS 2.32.3 + All plugins up to date.

      Pipeline: Build Step : 2.4
      Git client plugin : 2.3
    • Similar Issues:

      Description

      Pipeline from SCM does not expand parameters or environment variables 

      Steps to reproduce:

      • Create a new Pipeline with a String Parameter  "PIPELINE_BRANCH"
      • In the pipeline definition ; Select "Pipeline Script from SCM"
      • Enter the repository URL
      • In branch to build, enter the parameter  : ${PIPELINE_BRANCH}
      • Enter your script path
      • Run the job with a valid branch

       An error in thrown :
      hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/${PIPELINE_BRANCH}:refs/remotes/origin/${PIPELINE_BRANCH} --prune" returned status code 128:
      stdout:
       

      ${PIPELINE_BRANCH} is not  replaced by its value.

      Same issue with an environment variable.

      Expanding parameters/variable is working fine for a freestyle or matrix job.

       

       

       

       

       

        Attachments

          Issue Links

            Activity

            Hide
            medianick Nick Jones added a comment -

            We're seeing this same behavior today running Pipeline: Job (workflow-job) 2.32 (on Jenkins 2.176.1 LTS), with the "Lightweight checkout" checkbox unchecked. Is there a possibility that the system is still choosing a lightweight checkout essentially "on the fly", and if so, is there a way to force a heavyweight checkout?

            Show
            medianick Nick Jones added a comment - We're seeing this same behavior today running Pipeline: Job ( workflow-job ) 2.32 (on Jenkins 2.176.1 LTS), with the "Lightweight checkout" checkbox unchecked. Is there a possibility that the system is still choosing a lightweight checkout essentially "on the fly", and if so, is there a way to force a heavyweight checkout?
            Hide
            medianick Nick Jones added a comment -

            Aha – for us the issue was that we were reading a file from the workspace before the start of the the pipeline block, using a command like `def common = evaluate readTrusted('./Common.groovy')`. This seems to have bypassed the variable resolution. Removing this line caused the expected behavior to start again.

            Show
            medianick Nick Jones added a comment - Aha – for us the issue was that we were reading a file from the workspace before the start of the the pipeline block, using a command like `def common = evaluate readTrusted('./Common.groovy')` . This seems to have bypassed the variable resolution. Removing this line caused the expected behavior to start again.
            Hide
            docwarems Michael S. added a comment - - edited

            We have still a problem with Pipeline: Job 2.32 (even after upgrade to 2.36) on Jenkins 2.179. "Lightweight checkout" checkbox unchecked. Parameter Expansion does not work if parameter comes from "Properties File Path", It works, however, with parameter from "Properties Content". Too bad.

            BTW, our properties file is correct because it previously worked with a freestyle job.

            I created new issue JENKINS-60250.

            Show
            docwarems Michael S. added a comment - - edited We have still a problem with Pipeline: Job 2.32 (even after upgrade to 2.36) on Jenkins 2.179. "Lightweight checkout" checkbox unchecked. Parameter Expansion does not work if parameter comes from "Properties File Path", It works, however, with parameter from "Properties Content". Too bad. BTW, our properties file is correct because it previously worked with a freestyle job. I created new issue JENKINS-60250 .
            Hide
            tamerlaha ipleten added a comment -

            I could confirm that using `readTrusted` causes such error.

            Show
            tamerlaha ipleten added a comment - I could confirm that using `readTrusted` causes such error.
            Hide
            kirk_gm Max Golionko added a comment -

            We have same problem, but in our case we don't have readTrusted
            But we are using kubernetes with kubernetes-plugin, and we were using yaml file for pod configuration

              agent {
                kubernetes {
                  yamlFile "pod.yaml"
                }
              }  
            

            seems that underhood it calls readTrusted
            we tried to use

              agent {
                kubernetes {
                  yaml readFile("./pod.yaml")
                }
              }
            

            but this also didn't work
            only inline pod yaml helped to solve this issue

            agent {
                kubernetes {
                  yaml """
            apiVersion: v1
            kind: Pod
            spec:
              containers:
              - name: jnlp
                image: imagename
                imagePullPolicy: Always
            
            """
                }
              }    
            
            Show
            kirk_gm Max Golionko added a comment - We have same problem, but in our case we don't have readTrusted But we are using kubernetes with kubernetes-plugin, and we were using yaml file for pod configuration agent { kubernetes { yamlFile "pod.yaml" } } seems that underhood it calls readTrusted we tried to use agent { kubernetes { yaml readFile( "./pod.yaml" ) } } but this also didn't work only inline pod yaml helped to solve this issue agent { kubernetes { yaml """ apiVersion: v1 kind: Pod spec: containers: - name: jnlp image: imagename imagePullPolicy: Always """ } }

              People

              • Assignee:
                Unassigned
                Reporter:
                blatinville Bertrand Latinville
              • Votes:
                19 Vote for this issue
                Watchers:
                29 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: