I am just setting up Jenkins as a CI/build system on a host. Some pipelines would use Docker container for the build process. Jenkins itself is installed on the host system (so no Docker-in-Docker scenario!).
TL;DR:
Jenkins would “inject” the OS-Jenkins user into the Docker build container. Since the OS-Jenkins user is not known in the container, this leads to several difficulties. One of them: the executing user in the container has no HOME directory.
Problem arising: manual “git clone” commands in the build process would fail.
In more detail:
If you have a Jenkinsfile like this:
node {
docker.image("bitnami/minideb:latest").inside() {
echo "I am ..."
sh "id"
}
}
The Jenkins docker plugin would start the container with:
docker run -t -d -u 114:121 -w ...... bitnami/minideb:latest
Thus, it uses the local OS Jenkins user (happens to be UID 114 in my case) in the container. Since this user is not known in the container, it has e.g. no HOME directory.
Later in the build process, I need to execute
conan config install [email protected]:group/tools/conan.git
Nevermind that this is Conan. If you don’t know the “conan” tool: it is a dependency manager for C++. The only important thing here is that this above command would fetch conan settings from a repo and try to store the setting in a folder ~/.conan
. AND it does some “git clone” commands on its own when trying to resolve the dependencies.
I think where it stucks is when conan tries to perform manual “git clone” steps.
It tried to boil it down:
#!groovy
def docker_image = "cr.myownrepos.com/group/proj1/prj/algotest-launcher:1.6"
node {
docker.withRegistry('https://cr.myownrepo.com/', '78e560d3-73d7-4f36-a884-3001a913b202'){
docker.image(docker_image).inside() {
stage('Build') {
sshagent(['my_sshKey']) {
sh "export HOME=/tmp"
sh "git clone [email protected]:bmd-se/group/conan.git"
}
}
}
}
}
So this is only a “git clone”. Result: FAILURE with this output:
+ git clone [email protected]:bmd-se/tools/conan.git
Cloning into 'conan'...
No user exists for uid 114
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
In this case I cannot use the Jenkins git plugin instead, since the git command would be executed by the “conan” lib on its own.
So my question(s):
How can I provide a “normal” user from the container’s point of view, with a HOME directory and the ability to save something in it?
Or is there some other way I can conan to successfully clone some git repos?
Maybe the problem simply boils down to:
How can I manually do a “git clone somerepo” in a container launched by Jenkins docker plugin (when Jenkins injects a non-existent user with UID 114 into the container?