Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何使用其他用户的ssh密钥从jenkins推送到主分支_Git_Jenkins_Bitbucket - Fatal编程技术网

Git 如何使用其他用户的ssh密钥从jenkins推送到主分支

Git 如何使用其他用户的ssh密钥从jenkins推送到主分支,git,jenkins,bitbucket,Git,Jenkins,Bitbucket,我不知道这是否可以实现,但我需要在jenkins作业中将更改推送到bitbucket主分支存储库。让我们称之为repo1 该存储库的主分支具有仅为2个用户推送的配置分支权限。用户a和用户b。 此用户使用用户名和密码连接到bitbucket。 此外,该用户的appart_a和用户jenkins已在jenkins设置凭据中配置了连接到bitbucket的SSH密钥。 所以基本上,当Jenkins需要从BB中提取代码并构建一些应用程序时,使用这个凭证ID 但现在,一个新的工作要求,必须使詹金斯能够推进

我不知道这是否可以实现,但我需要在jenkins作业中将更改推送到bitbucket主分支存储库。让我们称之为repo1 该存储库的主分支具有仅为2个用户推送的配置分支权限。用户a和用户b。 此用户使用用户名和密码连接到bitbucket。 此外,该用户的appart_a和用户jenkins已在jenkins设置凭据中配置了连接到bitbucket的SSH密钥。 所以基本上,当Jenkins需要从BB中提取代码并构建一些应用程序时,使用这个凭证ID

但现在,一个新的工作要求,必须使詹金斯能够推进回购1主分支。 当然,我首先收到的是权限错误,因为只有用户a和用户b才能推送到master

因此,我现在尝试配置jenkis使用用户_a的凭证ID(将ha权限推送到主分支)

但是当我开始工作的时候,我得到了一个很好的信息

 git commit -m test
[master c078d06] gulp file generated
 Committer: Jenkins <jenkins@xxxx@xxxxx.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)
[Pipeline] sh
[workspace] Running shell script
+ git push origin master
remote: Permission denied to update branch master.To git@bitbucket.org:xxxxxx/repo1.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@bitbucket.org:xxxxxxx/repo1.git'
那么我如何才能做到这一点呢?我告诉jenkins使用用户凭证ID,但它不起作用。
此外,我无法在repo1主分支的bitbucket中添加用户jenkins,因为那里没有任何具有用户和密码的用户,jenkins只是使用ssh密钥连接到bitbucket。与user_a(也有user和pass)的方式相同。 如何使用用户\凭证ID(即在主分支中拥有权限的用户)将其推入主分支?显然,我试过的方法不起作用。
谢谢。-

如果用户使用用户名和密码,那么您应该将git url与https或http一起使用,对吗?不git@bitbucket.....that问题是,我不想在jenkins输出中对用户进行硬编码,还有其他方法吗?您不需要硬编码,您仍然可以使用credentialsId,但您必须更改url以使用https或httpany,了解如何替换特殊字符“@”例如,在密码,因为我尝试了这种方式,我得到:致命:无法访问'。我使用凭据Id的帐户也会遇到同样的问题,请为@找到它:%40。谢谢如果用户_a使用用户名和密码,那么您应该将git url与https或http一起使用,对吗?不git@bitbucket.....that问题是,我不想在jenkins输出中对用户进行硬编码,还有其他方法吗?您不需要硬编码,您仍然可以使用credentialsId,但您必须更改url以使用https或httpany,了解如何替换特殊字符“@”例如,在密码,因为我尝试了这种方式,我得到:致命:无法访问'。我使用凭据Id的帐户也会遇到同样的问题,请为@找到它:%40。谢谢
stage ('Pulling code from Bitbucket') {


        git branch: 'master',
                credentialsId: '2bbbbbbb-aaaaaaaa--xxxx-eeeeeeeeeee', #user_a credential ID
                url: 'git@bitbucket.org:xxxxxx/repo1.git'

            sh 'sed -i "s/running/walking/g" README.md' #just changing something in readme for test
            sh 'git add .'
            sh 'git commit -m "test"'
            sh 'git push '


        }