【问题标题】:Cloning Meson git subproject repositories from Docker?从 Docker 克隆 Meson git 子项目存储库?
【发布时间】:2022-07-15 16:38:54
【问题描述】:

我的项目托管在 GitHub 上并使用 Meson 构建系统。该项目大量使用了 Meson 的 subproject 功能:有一个顶级项目 repo 使用了多个“子”存储库。子存储库由 Meson 在“设置”阶段从 GitHub 克隆(见下文)。

我尝试使用 Jenkins 和 Docker 构建项目,但失败了。问题是从 Docker 容器访问 GitHub。

这是 Jenkins 管道:

pipeline
{
    agent { label 'ag1' }
    stages
    {
      stage('testrun')
        {
            agent
            {
                dockerfile
                {
                    label "ag2"
                }
            }
            steps
            {
                sh "meson setup builddir"
                sh "meson compile -C builddir"
            }

Jenkins 测试作业一直运行到 Meson 尝试从 GitHub 获取子项目存储库:meson setup builddir。错误是ERROR: Git command failed

我将如何解决这个问题?如何让 Jenkins 从 Docker 容器访问 GitHub?

【问题讨论】:

    标签: docker github jenkins jenkins-pipeline meson-build


    【解决方案1】:

    这里有一个解决方案。

    将此添加到 Jenkinsfile:

    dockerfile
    {
        args ('-v /home/jenkins/.ssh:/home/jenkins/.ssh')
        additionalBuildArgs ('--build-arg UID=$(id -u) --build-arg GID=$(id -g)')    
    }
    

    主机需要安装SSH key才能访问GitHub,并且这个key需要与Docker容器共享。这就是 args 行使用 -v (volume) 选项所做的事情。

    additionalBuildArgs 行将用户 id 设置为 jenkins,这也需要在 Dockerfile 中进行更改:

    # Create a Jenkins user
    ARG UNAME=jenkins
    # Get group and user id from outside "additionalBuildArgs" 
    ARG GID= 
    ARG UID= 
    # Add Jenkins user with proper host group id and user id
    RUN groupadd --gid $GID $UNAME
    RUN useradd --gid $GID --uid $UID --home-dir /home/$UNAME --create-home $UNAME
    

    现在jenkins 用户可以访问 GitHub 存储库,并且可以使用meson 命令。

    【讨论】:

      猜你喜欢
      • 2012-05-06
      • 2019-10-22
      • 2018-03-07
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多