詹金斯管道无法将代码签入git [英] jenkins pipeline cannot check code into git

查看:12
本文介绍了詹金斯管道无法将代码签入git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 jenkins 管道项目中,我可以很好地从 git 中签出代码...但是我们需要进行一些 git 签入,并且凭据显然没有被缓存.

In my jenkins pipeline project I can check code out from git fine... but we need to do some git checkins and the credentials apparently are not cached.

    stage 'Checkout'
    git url: 'git@bitbucket.org:myproj.git', branch: 'master', credentialsId: '012ce21d-e920-44ee-b6f7-08df8ab41de0', variable: 'CREDENTIALS'
    sh('git push') <---- fails with Permission denied (public key).

这里是示例输出:

Entering stage Checkout
Proceeding
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:myproj # timeout=10
Fetching upstream changes from git@bitbucket.org:myproj.git
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git -c core.askpass=true fetch --tags --progress git@bitbucket.org:myproj.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master cc35402c6b39e8a1f8d55a831d2d10215d47ccd0
 > git rev-list cc35402c6b39e8a1f8d55a831d2d10215d47ccd0 # timeout=10
[Pipeline] sh
[myproj] Running shell script
+ git push --set-upstream origin master
Warning: Permanently added the RSA host key for IP address '192.192.143.2' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

谁有好的解决办法?

谢谢

推荐答案

答案是使用sshagent jenkins插件:

the answer is to use the sshagent jenkins plugin:

http://getmesh.io/Blog/Jenkins+2+Pipeline+101

此插件为 git 访问注入 SSH_AUTH_SOCK 环境变量

this plugin injects a SSH_AUTH_SOCK environment variable for git access

这篇关于詹金斯管道无法将代码签入git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆