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

branchSpec variable resolution does not work when fetching pod definition

      We have the following job definition:

       

      pipelineJob("$FOLDER_NAME/k8s-promote") {
          displayName('k8s-promote')
          parameters {
              stringParam('RELEASE_TAG', '', ''. (Required)')
          }
          definition {
              cpsScmFlowDefinition {
                  scm {
                      gitSCM {
                          userRemoteConfigs {
                              userRemoteConfig {
                                  url '<private BB server>'
                                  credentialsId 'bitbucket-buildmaster'
                                  name ''
                                  refspec ''
                              }
                          }
                          branches {
                              branchSpec {
                                  name 'refs/tags/v-${RELEASE_TAG}'
                              }
                          }
                          browser {}
                          gitTool 'Default'
                      }
                  }
                  scriptPath 'Jenkinsfile-k8s'
                  lightweight false
              }
          }
      } 

       

      One of the steps tries to spawn a k8s agent base on a pod.yaml in the repo:

       

      stage('10. tests') {
          when {
              ...
          }
          agent {
              kubernetes {
                  label 'tests'
                  defaultContainer 'chrome'
                  yamlFile '.ci/chrome.yaml'
                  workspaceVolume emptyDirWorkspaceVolume(true)
              }
          }
          environment {
              ...
          }
          steps {
              ..
          }
      }

       

      As soon as the build comes to this step, it will fail with the following error:

       

      hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune -- origin +refs/tags/v-${RELEASE_TAG}:refs/remotes/origin/v-${RELEASE_TAG}" returned status code 128:stdout: stderr: fatal: couldn't find remote ref refs/tags/v-${RELEASE_TAG}
      	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)	at PluginClassLoader for git//jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:408)Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 770c278b-36aa-4c5f-bdba-13885c4b73eaCaused: java.io.IOException	at PluginClassLoader for git//jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:413)	at PluginClassLoader for scm-api//jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:219)	at PluginClassLoader for scm-api//jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:191)	at PluginClassLoader for scm-api//jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:174)	at PluginClassLoader for workflow-multibranch//org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:116)	at PluginClassLoader for workflow-multibranch//org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:93)	at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)	at java.base/java.lang.Thread.run(Unknown Source)Finished: FAILURE 

       

      I tested replacing the variable in the branchSpec definition with a concrete version and it was working, so I am assuming the variable is not substituted in this case.

       

      We continued with a workaround of providing the podYaml inline of the jenkinsfile and the job completed successfully.

       

       

       

          [JENKINS-75267] branchSpec variable resolution does not work when fetching pod definition

          There are no comments yet on this issue.

            Unassigned Unassigned
            leon_schiesswald Leon Schiesswald
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: