Jason_Lo
(Jason Lo)
January 21, 2021, 6:20am
1
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”.
stgraber
(Stéphane Graber)
January 21, 2021, 12:58pm
2
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.
Jason_Lo
(Jason Lo)
January 22, 2021, 1:29am
3
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.
Jason_Lo
(Jason Lo)
January 22, 2021, 1:56am
4
Investigate the issue by 2 changes.
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
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.
Jason_Lo
(Jason Lo)
January 22, 2021, 2:36am
5
$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.
Jason_Lo
(Jason Lo)
January 22, 2021, 3:10am
6
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
jenkins-slave.service
[Unit]
Description=Jenkins Slave
Wants=network.target
After=network.target
[Service]
ExecStart=/usr/bin/java -Xms512m -Xmx512m -jar /opt/jenkins/slave.jar -jnlpUrl http://${JENKINS_SERVER}/slave-agent.jnlp -secret ${SECRET}
User=jenkins
Restart=always
RestartSec=10
This file has been truncated. show original
supervisor-jenkins-slave.conf
[program:jenkins-slave]
command = /usr/bin/java -Xms512m -Xmx512m -jar /opt/jenkins/slave.jar -jnlpUrl http://${JENKINS_SERVER}/slave-agent.jnlp -secret ${SECRET}
stdout_logfile = syslog
redirect_stderr = true
user = jenkins
And it solves my issue 100%.