Lp: replacement issue using LxD vm as a Jenkins slave

I am using images:ubuntu/bionic/cloud to create vm, and jnlp slave connected to Jenkins master.
By initiating the LxD vm, I am using cloud-init to write a file into “/root/.gitconfig” with content as followed.

[user]
	email = username@canonical.com
        name = username

[url "git+ssh://username@git.launchpad.net/"]
        insteadof = lp:

But when I run Jenkins configuration with “git clone lp:~project-team/project/+git/repository”, it shows the following error.

**14:06:18** ssh: Could not resolve hostname lp: Temporary failure in name resolution 
**14:06:18** fatal: Could not read from remote repository.

I printed out with whoami, and the user shows “root”.

Maybe Jenkins somehow isn’t using .gitconfig when calling git?

You could probably strace the jenkins agent to see exactly what it’s calling and what files are read.

I tried git config --global and got this

23:01:25 + git config --global user.email ****@canonical.com
23:01:25 fatal: $HOME not set

I think the main cause is $HOME not been set.
I didn’t hit this when using Vagrant VM as the JNLP slave.
The only difference I can guess is when using LxD vm I use “root” as the user to connect.
Keep investigating.

Investigate the issue by 2 changes.

  1. Put agent.jar elsewhere than /root [This has been prove NOT relevant]
    Original:
    java -jar /root/agent.jar -jnlpUrl http://jenkins.ip.:8080/computer/oem-iot-focal-1/slave-agent.jnlp -secret xxxxxx -workDir "/home/user"
    Updated:
    java -jar /home/user/agent.jar -jnlpUrl http://jenkins.ip.:8080/computer/oem-iot-focal-1/slave-agent.jnlp -secret xxxxxx -workDir "/home/user"

This solve the issue $HOME not been set, and now it shows /root as home but it comes another issue.

**09:46:14** + git clone 'lp:~project-team/project/+git/oem-repo' 
**09:46:14** fatal: open /dev/null or dup failed: No such file or directory
  1. To solve this, create /dev/null in LxD vm
    mknod /dev/null c 1 3
    chmod 666 /dev/null

Step 1. proved that manually run JNLP connect works well.

$HOME not been set issue still exists when I use cloud-init to make this a systemd service and start when LxD vm boot up.

java -jar /home/user/agent.jar -jnlpUrl http://jenkins.ip.:8080/computer/oem-iot-focal-1/slave-agent.jnlp -secret xxxxxx -workDir "/home/user"

I think it is not because agent.jar under /root, but because of using systemd to run jnlp connect.
When I use manual run, it works well.

Instead of creating a systemd service to run another bash script (with & to run in background), I re-write the systemd service following the guidance of this

And it solves my issue 100%.