【问题标题】:Authentication error configuring Jenkins to work with Git Bitbucket repo配置 Jenkins 以使用 Git Bitbucket 存储库的身份验证错误
【发布时间】:2014-01-04 14:36:31
【问题描述】:

我正在尝试在 Windows 7 环境中配置 Jenkins 以使用 Bitbucket 上的 Git 存储库,但是当我尝试进行构建时 - 我收到以下错误。

这是我正在使用的存储库 URL:

https://<MY_ID>:<MY_PASSWORD>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git

不确定我是否需要为 Jenkins-Bitbucket 生成密钥,如果需要,谁能提供有关如何为 Windows 生成密钥的详细说明?

Started by user anonymous
Building in workspace C:\Users\<MY_NAME>\.jenkins\workspace\<MY_PROJECT>
Fetching changes from the remote Git repository
Fetching upstream changes from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
FATAL: Failed to fetch from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
hudson.plugins.git.GitException: Failed to fetch from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:612)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:836)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:861)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1414)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:652)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:561)
    at hudson.model.Run.execute(Run.java:1678)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git +refs/heads/*:refs/remotes/<MY_ID>/*" returned status code 128:
stdout: 
stderr: fatal: Authentication failed for 'https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git/'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1098)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:984)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:68)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:217)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.fetch(CliGitAPIImpl.java:223)
    at hudson.plugins.git.GitAPI.fetch(GitAPI.java:229)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:610)
    ... 10 more

【问题讨论】:

    标签: git jenkins bitbucket


    【解决方案1】:

    好的,这对我有用,但首先,我的设置如下:

    1. Windows 7
    2. Jenkins(带有 Git 插件)
    3. 吉特
    4. Bitbucket 帐户

    我开始关注这个tutorial。它适用于 Windows,您只需双击“C:\Program Files (x86)\Git”中的“Git Bash”并按照说明生成 ssh 密钥。我只需要执行第 2 步和第 3 步。

    注意:我生成的密钥没有密码!这是我让它工作的唯一方法......

    然后,使用文本编辑器打开在“C:\Users\YOUR_WINDOWS_USER_NAME\.ssh”中生成的公钥文件“id_rsa.pub”并复制内容。获得公钥后,您需要在 Bitbucket 中注册,转到“管理帐户”->“SSH 密钥”->“添加密钥”。粘贴您的公钥并保存。

    为了测试密钥,我运行了这个命令:

    $ ssh -T git@bitbucket.org
    logged in as <USER_ID>.
    
    You can use git or hg to connect to Bitbucket. Shell access is disabled.
    

    现在您需要向 Jenkins 注册您的私钥:转到“Credentials”->“Global credentials”->“Add Credentials”,输入您的用户名、描述(可选),选择“From a file on Jenkins master " 并输入 C:\Users\YOUR_WINDOWS_USER_NAME\.ssh\id_rsa。

    最后一步是配置 Jenkins 作业。在“Source Code Management”下,选择“Git”,在“Repository URL”下,输入:

    git@bitbucket.org:<USER_ID>/<REPO_NAME>.git
    

    在“凭据”下,选择您刚刚创建的凭据。

    注意:确保当您转到“管理 Jenkins”->“配置系统”->“Git”时,“Git 可执行文件的路径”设置为“C:\Program Files (x86)\Git \cmd\git.exe"。

    按照这些步骤,我能够从存储库中提取我的代码。

    【讨论】:

    • +1。这遵循我的回答并使用我提到的链接。我也喜欢一开始没有密码,至少让它工作。如果您有密码保护的私有 ssh 密钥,则需要一个 ssh 代理:stackoverflow.com/a/14913230/6309
    【解决方案2】:

    不确定是否需要为 Jenkins-Bitbucket 生成密钥

    钥匙?就像在“ssh 密钥”中一样?如果您使用的是 https url(如this question),当然不会。登录名和密码应该足够了。

    仔细检查您的登录名/密码和网址:区分大小写。

    确保您的密码没有任何特殊字符(您需要percent-encode,如this case)。


    对于使用 ssh url,您可以关注“Use the SSH protocol with Bitbucket”(在setting up ssh 之后)。
    确保将 Jenkins 作业配置中的 git repo 的 url 修改为:

    git@bitbucket.org:accountname/reponame.git
    # or
    ssh://git@bitbucket.org/accountname/reponame.git
    

    但是,请确保 Jenkins 以存储 ssh 密钥的用户身份运行:请参阅“Jenkins finds cannot find ssh key”和此BitBucket thread。 (Check also your firewall)

    【讨论】:

    • 与“ssh”完全一样,在这种情况下,URL 也会更改为“ssh”。不知何故,“https”在 Jenkins 中不起作用,而我在 Eclipse 中的 EGit 插件已配置并且可以在“https”(未编码)上正常工作。这就是为什么我一直在寻找通过“ssh”配置它的分步说明。
    • @user1004462 我了解,但您的问题明确指出您正在使用 https 网址...
    • @user1004462 我已经编辑了我的答案以解决您问题的 ssh 方面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2021-12-30
    • 1970-01-01
    • 2020-10-19
    • 2018-02-15
    • 1970-01-01
    相关资源
    最近更新 更多