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

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

问题描述

在我的jenkins管道项目中,我可以从git中检查代码......但是我们需要做一些git checkins,并且证书显然不会被缓存。

  stage'Checkout'
git url:'git@bitbucket.org:myproj.git',分支:'master',credentialsId:'012ce21d-e920-44ee-b6f7-08df8ab41de0 ',变量:'CREDENTIALS'
sh('git push')< - 失败且权限被拒绝(公钥)。

这里是示例输出:

 进入阶段结账
进行中
[管道] git
> git rev-parse --is-inside-work-tree#timeout = 10
从远程Git仓库获取更改
> git config remote.origin.url git@bitbucket.org:myproj#timeout = 10
从git@bitbucket.org获取上游变更:myproj.git
> git --version#timeout = 10
使用GIT_SSH设置凭证
> 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
检出版本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分支-D master#timeout = 10
> git checkout -b master cc35402c6b39e8a1f8d55a831d2d10215d47ccd0
> git rev-list cc35402c6b39e8a1f8d55a831d2d10215d47ccd0#timeout = 10
[Pipeline] sh
[myproj]运行shell脚本
+ git push --set-upstream origin master
警告:永久添加RSA主机密钥的IP地址'192.192.143.2'到已知主机列表。
权限被拒绝(publickey)。
致命:无法从远程存储库读取。

任何人都可以很好的解决这个问题吗?

感谢

解决方案

答案是使用sshagent jenkins插件:

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



这个插件为git访问注入一个SSH_AUTH_SOCK环境变量


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).

here is sample output:

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.

anyone have a good solution to this?

thanks

解决方案

the answer is to use the sshagent jenkins plugin:

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

this plugin injects a SSH_AUTH_SOCK environment variable for git access

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

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