Hi, I’m currently to bake a jenkins image with the Google cloud Platform.
My template.json file
{
“variables” : {
“service_account” : “…/…/eventer-jenkins-cluster-f8bd7a6e0d54.json”,
“project”: “eventer-jenkins-cluster”,
“zone”: “us-central1-a”,
“ssh_key” : “./ssh”
},
“builders” : [
{
“type”: “googlecompute”,
“image_name” : “jenkins-master-v22041”,
“account_file”: “{{user service_account
}}”,
“project_id”: “{{user project
}}”,
“source_image”: “centos-stream-8-v20220317”,
“ssh_username”: “packer”,
“zone”: “{{user zone
}}”
}
],
“provisioners” : [
{
“type” : “file”,
“source” : “./scripts”,
“destination” : “/tmp/”
},
{
“type” : “file”,
“source” : “./config”,
“destination” : “/tmp/”
},
{
“type” : “file”,
“source” : “{{user ssh_key
}}”,
“destination” : “/tmp/id_rsa”
},
{
“type” : “shell”,
“script” : “./setup.sh”,
“execute_command” : “sudo -E -S sh ‘{{ .Path }}’”
}
]
}
My setup.sh
#!/bin/bash
echo “Install Jenkins stable release”
yum remove -y java
yum install -y java-1.8.0-openjdk
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install -y jenkins
chkconfig jenkins on
echo “Install git”
yum install -y git
echo “Setup SSH key”
mkdir -p /var/lib/jenkins/.ssh
touch /var/lib/jenkins/.ssh/known_hosts
chown -R jenkins:jenkins /var/lib/jenkins/.ssh
chmod 700 /var/lib/jenkins/.ssh
mv /tmp/id_rsa /var/lib/jenkins/.ssh/id_rsa
chmod 600 /var/lib/jenkins/.ssh/id_rsa
chown -R jenkins:jenkins /var/lib/jenkins/.ssh/id_rsa
echo “Configure Jenkins”
mkdir -p /var/lib/jenkins/init.groovy.d
mv /tmp/*.groovy /var/lib/jenkins/init.groovy.d/
mv /tmp/jenkins /etc/sysconfig/jenkins
chmod +x /tmp/install-plugins.sh
bash /tmp/install-plugins.sh
service jenkins start
I keep getting these lines of error:
googlecompute: chown: invalid user: ‘jenkins:jenkins’
googlecompute: Configure Jenkins
==> googlecompute: mv: cannot stat ‘/tmp/*.groovy’: No such file or directory
==> googlecompute: mv: cannot stat ‘/tmp/jenkins’: No such file or directory
==> googlecompute: chmod: cannot access ‘/tmp/install-plugins.sh’: No such file or directory
==> googlecompute: bash: /tmp/install-plugins.sh: No such file or directory
==> googlecompute: Redirecting to /bin/systemctl start jenkins.service
==> googlecompute: Failed to start jenkins.service: Unit jenkins.service not found.
Please what mistake am I making?