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

PipelineScript from SCM does not support job parameters

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • pipeline
    • Jenkins 1.6.4.6
      Workflow-cps 1.15

      On normal maven/freestyle jobs the checked out branch can be parameterized with job parameters.
      The following job uses the workflow plugin to pull a groovy script from scm.
      Here the ${branch} variable is not substituted.

      <?xml version="1.0" encoding="UTF-8"?>
      <flow-definition plugin="workflow-job@1.15">
          <actions />
          <description>WARNING: this jobs fails due to not substituting ${branch} on ckeckout.</description>
          <keepDependencies>false</keepDependencies>
          <properties>
              <hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.3">
                  <useBuildBlocker>false</useBuildBlocker>
                  <blockLevel>GLOBAL</blockLevel>
                  <scanQueueFor>DISABLED</scanQueueFor>
                  <blockingJobs />
              </hudson.plugins.buildblocker.BuildBlockerProperty>        
              <hudson.model.ParametersDefinitionProperty>
                  <parameterDefinitions>
                      <hudson.model.StringParameterDefinition>
                          <name>releaseVersion</name>
                          <description />
                          <defaultValue />
                      </hudson.model.StringParameterDefinition>
                      <hudson.model.StringParameterDefinition>
                          <name>branch</name>
                          <description />
                          <defaultValue>6.4.x</defaultValue>
                      </hudson.model.StringParameterDefinition>                
                  </parameterDefinitions>
              </hudson.model.ParametersDefinitionProperty>
          </properties>
          <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@1.15">
              <scm class="hudson.plugins.git.GitSCM" plugin="git@2.4.3">
                  <configVersion>2</configVersion>
                  <userRemoteConfigs>
                      <hudson.plugins.git.UserRemoteConfig>
                          <url>ssh://git@someSever:7999/SomeRepo.git</url>
                      </hudson.plugins.git.UserRemoteConfig>
                  </userRemoteConfigs>
                  <branches>
                      <hudson.plugins.git.BranchSpec>
                          <name>refs/heads/${branch}</name><!-- THIS should be substituted but isn't -->
                      </hudson.plugins.git.BranchSpec>
                  </branches>
                  <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
                  <submoduleCfg class="list" />
              </scm>
              <scriptPath>releasePipeline.groovy</scriptPath>
          </definition>
          <triggers />
      </flow-definition>
      

      The result is:

      Started by user Dreyer Ulf
       > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
       > git config remote.origin.url ssh://git@imbvl2vm294.bosch-si.com:7999/brm/vr-releng__release-scripts.git # timeout=10
      Fetching upstream changes from ssh://git@imbvl2vm294.bosch-si.com:7999/brm/vr-releng__release-scripts.git
       > git --version # timeout=10
       > git -c core.askpass=true fetch --tags --progress ssh://git@someServer.com:7999/someRepo.git +refs/heads/*:refs/remotes/origin/*
       > git rev-parse refs/remotes/origin/${branch}^{commit} # timeout=10
       > git rev-parse refs/remotes/origin/refs/heads/${branch}^{commit} # timeout=10
       > git rev-parse refs/heads/${branch}^{commit} # timeout=10
      ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
      Finished: FAILURE
      

      when it really should substitute ${branch} with 6.4.x as it does in the rest of the script.

          [JENKINS-33719] PipelineScript from SCM does not support job parameters

          Ulf Dreyer created issue -

          Martin Wirth added a comment -

          Hello there,

          i just stumbled over the same issue as i was using a trigger job (using Stash Pull Request Builder Plugin) to trigger our testing build that is actually using a pipeline script from git. I already assured, that the missing parameters are provided by checking the "parameters" view.

          We are currently using a workaround by having a little pipeline script inside the corresponding task, that does the parameterized checkout of the pipleine script in SCM for us:

          // workaround to check out the Jenkinsfile of the tag because parameters are not replaced
          // when using the "Pipeline script from SCM" option
          node('xpro-build') {
              stage 'Load Jenkinsfile From SCM'
              checkout poll:false, scm: [
                  $class: 'GitSCM',
                  branches: [[name: "origin/pr/${pullRequestId}/from"]],
                  userRemoteConfigs: [[
                      url: "ssh://git@<host>:<port>/${destinationRepositoryOwner}/${destinationRepositoryName}.git",
          			credentialsId: '<credentials>', 
                      refspec: '+refs/pull-requests/*:refs/remotes/origin/pr/*'
                  ]]
              ]
              load 'Jenkinsfile-test'
          }
          

          Please let me know if i can help with further details.

          Martin Wirth added a comment - Hello there, i just stumbled over the same issue as i was using a trigger job (using Stash Pull Request Builder Plugin) to trigger our testing build that is actually using a pipeline script from git. I already assured, that the missing parameters are provided by checking the "parameters" view. We are currently using a workaround by having a little pipeline script inside the corresponding task, that does the parameterized checkout of the pipleine script in SCM for us: // workaround to check out the Jenkinsfile of the tag because parameters are not replaced // when using the "Pipeline script from SCM" option node( 'xpro-build' ) { stage 'Load Jenkinsfile From SCM' checkout poll: false , scm: [ $class: 'GitSCM' , branches: [[name: "origin/pr/${pullRequestId}/from" ]], userRemoteConfigs: [[ url: "ssh: //git@<host>:<port>/${destinationRepositoryOwner}/${destinationRepositoryName}.git" , credentialsId: '<credentials>' , refspec: '+refs/pull-requests/*:refs/remotes/origin/pr/*' ]] ] load 'Jenkinsfile-test' } Please let me know if i can help with further details.
          Martin Wirth made changes -
          Labels New: param
          Martin Wirth made changes -
          Labels Original: param New: parameterized

          Peter Nijssen added a comment -

          I just want to confirm that I am also unable to use job parameters within the SCM. (Git in my case).

          Peter Nijssen added a comment - I just want to confirm that I am also unable to use job parameters within the SCM. (Git in my case).

          Fixing this bug / adding this feature would be incredibly useful. I'd be glad to help in way.

          Matthew Gyurgyik added a comment - Fixing this bug / adding this feature would be incredibly useful. I'd be glad to help in way.

          I’ve exactly the same problem. This bug is blocking me from using pipeline jobs.

          Mathias Schreck added a comment - I’ve exactly the same problem. This bug is blocking me from using pipeline jobs.
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-28447 [ JENKINS-28447 ]
          Jesse Glick made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

          jon duffy added a comment -

          Hi mawi Where are the variables in your script being set?

          eg ${destinationRepositoryName} ?

          Thanks

          jon duffy added a comment - Hi mawi Where are the variables in your script being set? eg ${destinationRepositoryName} ? Thanks

            jglick Jesse Glick
            ulf_dreyer Ulf Dreyer
            Votes:
            12 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: