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

Pipeline checkout fails jenkins-gitclient-pass.sh: line 3: cat: command not found

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None

      When running pipelines on Jenkins 2.331 the initial SCM checkout/clone fails when the pipeline definition specifies a global agent context with an OS that differs from the OS of the controller.

       Started by user xxxxxx
      Running as xxxxx
      Checking out git https://xxxxxxxxxxx/jenkins-pipeline.git into /apps/jenkins/jobs/...../workspace@script to read resources/pipelines/......groovy
      The recommended git tool is: /usr/bin/git
      using credential svc_xxxxxxxxxxxxx
       > /usr/bin/git rev-parse --resolve-git-dir /apps/jenkins/jobs/....../workspace@script/.git # timeout=10
      Fetching changes from the remote Git repository
       > /usr/bin/git config remote.origin.url https://xxxxxx/jenkins-pipeline.git # timeout=10
      Fetching upstream changes from https://xxxxxxx/jenkins-pipeline.git
       > /usr/bin/git --version # timeout=10
       > git --version # 'git version 2.24.4'
      using GIT_ASKPASS to set credentials Bitbucket Server (xxxxxxx)
       > /usr/bin/git fetch --tags --force --progress -- https://xxxxxxx/jenkins-pipeline.git +refs/heads/*:refs/remotes/origin/* # timeout=10
      ERROR: Error fetching remote repo 'origin'
      hudson.plugins.git.GitException: Failed to fetch from https://xxxxxxx/jenkins-pipeline.git
      	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
      	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
      	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
      	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:154)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:68)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
      	at hudson.model.ResourceController.execute(ResourceController.java:101)
      	at hudson.model.Executor.run(Executor.java:442)
      Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --force --progress -- https://xxxxxxx/jenkins-pipeline.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
      stdout: 
      stderr: /apps/jenkins/jobs/...../workspace@script@tmp/jenkins-gitclient-pass2348591706542264259.sh: line 3: cat: command not found
      error: unable to read askpass response from '/apps/jenkins/jobs/....../workspace@script@tmp/jenkins-gitclient-pass2348591706542264259.sh'
      fatal: could not read Username for 'https://xxxxxx.com': terminal prompts disabled
      
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:618)
      	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
      	... 8 more
      ERROR: Error fetching remote repo 'origin'
      ERROR: Maximum checkout retry attempts reached, aborting
      Finished: FAILURE

      Our controller runs on Linux and we have a pipeline that runs exclusively on windows agents. The pipeline declares a global contexts for certain stages that must run on a single agent vs others that run in parallel on all agents

      pipeline {
          agent {
              node {
                  label MASTER_NODE
              }
          }
      

      When running this pipeline the above error is thrown and the pipeline fails. If i rerun the pipeline but set the agent to "agent: none", then the checkout completes as expected, but our pipeline fails due to missing context.

      Given the error and the fact this only seems to happen with global agent context where the agents OS differs from the controllers OS, I assume something is overriding the path with the path from the Windows agent.
      To partially prove this, i deployed a custom version of the git-client-plugin, where i modified createUnixStandardAskpass to explicitly output the full path

          private File createUnixStandardAskpass(StandardUsernamePasswordCredentials creds, File usernameFile, File passwordFile) throws IOException {
              File askpass = createTempFile("pass", ".sh");
              try (PrintWriter w = new PrintWriter(askpass, encoding)) {
                  w.println("#!/bin/sh");
                  w.println("case \"$1\" in");
                  w.println("Username*) /bin/cat " + unixArgEncodeFileName(usernameFile.getAbsolutePath()) + " ;;");
                  w.println("Password*) /bin/cat " + unixArgEncodeFileName(passwordFile.getAbsolutePath()) + " ;;");
                  w.println("esac");
              }
              askpass.setExecutable(true, true);
              // fixSELinuxLabel(askpass, "ssh_exec_t");
              return askpass;
          }
      

      The checkout then completes correctly.

      I found something similar, but in a plugin we don't use
      https://issues.jenkins.io/browse/JENKINS-55948?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
      https://github.com/jenkinsci/git-parameter-plugin/commit/a39eac169d72df2b6e3b10a4050b18030770150b?diff=split

            Unassigned Unassigned
            ffsetit Pete Barnes
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: