简体   繁体   中英

Jenkins Pipeline and SSH keys - Git agent works, SSH Agent doesn't

I'm trying to use Git repos in my pipeline, but I'm running into authentication issues. Ultimately I need to use 'tsrc' but authentication is failing even on simple examples.

Here's the simplest example I can come up with. This works.

  stage('Hello') {
    steps {
      git branch: 'master', credentialsId: 'Github-SSH', url: 'git@****'
      echo 'Hello World'
    }
  }

This doesn't.

steps {
  withCredentials([sshUserPrivateKey(credentialsId: 'Github-SSH', keyFileVariable: 'KEY_FILE')])             
    {
    sh '''
            eval `ssh-agent -s`
            ssh-add ${KEY_FILE}
            git clone git@****
    '''
    }
  }
}

The second example gives the error:

Host key verification failed.

尝试用 """ 替换 ```,这样${KEY_FILE}被解释为一个变量。PS 当声明性管道的行为与 Groovy 不同时,我遇到了行为。所以,不确定。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM