Hello everyone
I am trying to follow this tutorial to do distributed jenkins build
https://cloud.google.com/architecture/using-jenkins-for-distributed-builds-on-compute-engine
and I am getting inconsistent behaviour from packer when trying to use to build a jenkins agent. I modified the jenkis-agent.json to install Java 11 likes this:
{
"builders": [
{
"type": "googlecompute",
"project_id": "elite-impact-378112",
"source_image_family": "ubuntu-2004-lts",
"source_image_project_id": "ubuntu-os-cloud",
"zone": "us-central1-a",
"disk_size": "50",
"image_name": "jenkins-agent-{{timestamp}}",
"image_family": "jenkins-agent",
"ssh_username": "ubuntu"
}
],
"provisioners": [
{
"type": "shell",
"inline": ["sudo apt-get update && sudo apt-get install -y openjdk-11-jdk"]
}
]
}
because that is what I have running on the jenkins master node on my laptop. Now the first time I ran the packer build command in the gcloud shell
./packer build jenkins-agent.json
I got the following error
[0;32m googlecompute: The following packages have unmet dependencies:[0m
[0;32m googlecompute: openjdk-11-jdk : Depends: openjdk-11-jre (= 11.0.18+10-0ubuntu1~20.04.1) but it is not going to be installed[0m
[0;32m googlecompute: Depends: openjdk-11-jdk-headless (= 11.0.18+10-0ubuntu1~20.04.1) but it is not going to be installed[0m
[0;32m googlecompute: Recommends: libxt-dev but it is not installable[0m
[1;31m==> googlecompute: E: Unable to correct problems, you have held broken packages.
Now since I was running this in the gcloud shell, most of the output was running off the screen. I wanted to see this output so decided to run the command again but redirecting to a file like this:
./packer build jenkins-agent.json > packer_build_output.txt
The funny thing that now happened was that the jenkins agent was successfully built this time with no change on my end other than redirecting the output. I was also able to succesfully perform the "Hello World" test in the tutorial. I now decided that I wanted to pull the "Hello World" code from GitHub so I modified the jenkins-agent.json to also install git. This packer build was also successful and the subsequent jenkins build was also successful. I now decided that I wanted to use Maven to build the code so I modified the jenkins-agent.json again to also install maven. This packer build failed. Before trying to debug the error, I wanted to make sure that the previous build of just Java 11 and git would still work so I removed the install maven code and ran the packer build again. This also failed with the original error message I posted earlier. Please I would appreciate any clues as to the inconsistency of packer because it is really driving me up the wall. Thank you
Hello @imonike,
Welcome to Google Cloud Community!
Based on the error you posted, you have held broken packages error when trying to install
openjdk-11-jdk
This is because a conflict was avoided by holding them down. That is why it is not installing, upgrading, downgrading, or removing. You can try:
1. Installing aptitude by running
sudo apt-get install -y aptitude
2. then run this for your held packages
sudo aptitude install <packagename>
This will give you more information about the problem. It will also tell you exactly what's wrong and offers you automatically to perform the fix on your behalf.
I tried what you suggested but it seems like google cannot found "aptitude" either. So at the end it doesn't create the instance.