Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Jenkins to build a private GitHub Rust project with a private GitHub dependency?

I have a private GitHub Rust project that depends on another private GitHub Rust project and I want to build the main one with Jenkins. I have called the organization Organization and the dependency package subcrate in the below code.

My Jenkinsfile looks something like

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

  stages {

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

    etc...

  }
}

I have tried the following in Cargo.toml to reference the dependency, it works fine on my machine

[dependencies]
subcrate = { git = "ssh://[email protected]/Organization/subcrate.git", tag = "0.1.0" }

When Jenkins runs I get the following error

+ cargo build

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

    Updating git repository `ssh://[email protected]/Organization/subcrate.git`

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

Caused by:

  Unable to update ssh://[email protected]/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

How can I get Cargo to access this GitHub repository? Do I need to inject the GitHub credentials onto the slave? If so, how can I do this? Is it possible to use the same credentials Jenkins uses to checkout the main crate in the first place?

I installed the ssh-agent plugin and updated my Jenkinsfile to look like this

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

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

    etc...

  }
}

I get the error

+ ssh -vvv -T [email protected]

No user exists for uid 113

script returned exit code 255
like image 275
Ross MacArthur Avatar asked Nov 22 '25 13:11

Ross MacArthur


1 Answers

Okay, I figured it out, No user exists for uid error is because of a mismatch between the users in the host /etc/passwd and the container /etc/passwd. This can be fixed by mounting /etc/passwd.

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

Then

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

Works just fine

like image 166
Ross MacArthur Avatar answered Nov 24 '25 06:11

Ross MacArthur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!