首页 文章

如何让Jenkins通过作曲家查看私人供应商回购

提问于
浏览
1

我有一个我想用Jenkins Build 的项目 . 该项目托管在一个私有的GitHub仓库中,我将SSH公钥放在我的用户“deploy”的GitHub中 .

由于构建配置中的Jenkins git插件部分中的部署凭证,项目得到了很好的检查 . 但是,通过构建步骤命令加载在同一GitHub组织中作为私有托管的供应商lib:

php composer.phar install -o --prefer-dist --no-dev

我已经安装了Jenkins git插件,以便通过私有SSH密钥检查来自GitHub的主要仓库 . 但是当作曲家试图检查我得到的子项目时

Failed to clone the git@github.com:Organisation/Repo.git repository, try running in interactive mode so that you can enter your GitHub credentials

我试图让作曲家命令作为一个不同的用户运行,但没有成功,例如:

su - deploy -c 'php composer.phar install -o --prefer-dist --no-dev'

反正看起来很奇怪 . 我想找出让作曲家完成工作的正确方法 . 想?

1 回答

  • 2

    Jenkins实际上是以"jenkins"用户身份运行shell命令 . 这意味着"jenkins"需要访问GitHub . 然后所有 git@github.com:Organisation/Repo.git 将无需额外凭据即可运行 .

    这里解释了如何通过SSH授予Jenkins访问GitHub的权限

    # Login as the jenkins user and specify shell explicity,
    # since the default shell is /bin/false for most
    # jenkins installations.
    sudo su jenkins -s /bin/bash
    
    ssh-keygen -t rsa -C "your_email@example.com"
    # Copy ~/.ssh/id_rsa.pub into your Github
    
    # Allow adding the SSH host key to your known_hosts
    ssh -T git@github.com
    
    # Exit from su
    exit
    

    灵感来自:Managing SSH keys within Jenkins for Git

相关问题