如何使用Jenkins构建具有私有GitHub依赖性的私有GitHub Rust项目?

时间:2018-07-20 11:49:23

标签: jenkins github rust

我有一个私有GitHub Rust项目,该项目依赖于另一个私有GitHub Rust项目,我想用Jenkins构建主要项目。我在下面的代码中称组织Organization和依赖项包subcrate

我的Jenkinsfile看起来像

pipeline {
  agent {
    docker {
      image 'rust:latest'
    }
  }

  stages {

    stage('Build') {
      steps {
        sh "cargo build"
      }
    }

    etc...

  }
}

我在Cargo.toml中尝试了以下内容来引用依赖关系,它在我的机器上可以正常工作

[dependencies]
subcrate = { git = "ssh://git@ssh.github.com/Organization/subcrate.git", tag = "0.1.0" }

Jenkins运行时,出现以下错误

+ cargo build

    Updating registry `https://github.com/rust-lang/crates.io-index`

    Updating git repository `ssh://git@github.com/Organization/subcrate.git`

error: failed to load source for a dependency on `subcrate`

Caused by:

  Unable to update ssh://git@github.com/Organization/subcrate.git?tag=0.1.0#0623c097

Caused by:

  failed to clone into: /usr/local/cargo/git/db/subcrate-3e391025a927594e

Caused by:

  failed to authenticate when downloading repository

attempted ssh-agent authentication, but none of the usernames `git` succeeded

Caused by:

  error authenticating: no auth sock variable; class=Ssh (23)

script returned exit code 101

如何让Cargo访问此GitHub存储库?我需要将GitHub凭证注入到从属服务器上吗?如果是这样,我该怎么做?可以使用詹金斯首先检出主要箱子的相同凭证吗?

我安装了ssh-agent插件并更新了Jenkinsfile,使其看起来像这样

pipeline {
  agent {
    docker {
      image 'rust:latest'
    }
  }

  stages {
    stage('Build') {
      steps {
        sshagent(credentials: ['id-of-github-credentials']) {
          sh "ssh -vvv -T git@github.com"
          sh "cargo build"
        }
      }
    }

    etc...

  }
}

我得到了错误

+ ssh -vvv -T git@github.com

No user exists for uid 113

script returned exit code 255

1 个答案:

答案 0 :(得分:0)

好的,我发现了,No user exists for uid错误是由于主机/etc/passwd和容器/etc/passwd中的用户不匹配。可以通过安装/etc/passwd来解决。

  agent {
    docker {
      image 'rust:latest'
      args '-v /etc/passwd:/etc/passwd'
    }
  }

然后

  sshagent(credentials: ['id-of-github-credentials']) {
    sh "cargo build"
  }

工作正常