Home > database >  Failed to install Jenkins with JDK 11 on Amazon EC2 Linux 2 AMI with Packer
Failed to install Jenkins with JDK 11 on Amazon EC2 Linux 2 AMI with Packer

Time:11-04

I try to install EC2 instance, with pre-installed Jenkins, using the following Packer configuration:

The most important part here is setup.sh script, which installs Jenkins and Java:

#!/bin/bash

echo "Installing Amazon Linux extras"
amazon-linux-extras install epel -y

echo "Install Jenkins stable release"
yum remove -y java
yum install -y java-11-openjdk-devel
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 /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/scripts/*.groovy /var/lib/jenkins/init.groovy.d/
chown -R jenkins:jenkins /var/lib/jenkins/init.groovy.d
mv /tmp/config/jenkins /etc/sysconfig/jenkins
chmod  x /tmp/config/install-plugins.sh
bash /tmp/config/install-plugins.sh
service jenkins start

See all other configuration files by this link:

https://github.com/mlabouardy/pipeline-as-code-with-jenkins/tree/master/chapter4/distributed/master

When I run:

packer build template.json

I get the following exception:

==> amazon-ebs: Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.

Everything works perfectly, If I use:

yum install -y java-1.8.0-openjdk

instead of:

yum install -y java-11-openjdk-devel

I'm able to start Jenkins, but I see the following warning:

Using Java 8 with the latest Jenkins is not recommended

Does anyone know how to make this configuration work with Java 11 ?

P.S. As a Source Amazon Machine Image for Packer I use:

Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-02e136e904f3da870 (64-bit x86) / ami-0e341fcaad89c3650 (64-bit Arm)

It is available in the "us-east-1" region ("source_ami" : "ami-02e136e904f3da870" - the exact id of Amazon Linux 2 AMI depends on the region)

Here is the Packer template.json, which is used for baking Jenkins Image from the Source Image:

{
    "variables" : {
        "region" : "us-east-1",
        "aws_profile": "ops-account",
        "source_ami" : "ami-02e136e904f3da870",
        "instance_type": "t2.micro",
        "ssh_key": "./jenkins_ssh"
    },
    "builders" : [
        {
            "type" : "amazon-ebs",
            "profile" : "{{user `aws_profile`}}",
            "region" : "{{user `region`}}",
            "instance_type" : "{{user `instance_type`}}",
            "source_ami" : "{{user `source_ami`}}",
            "ssh_username" : "ec2-user",
            "ami_name" : "jenkins-master-2.204.1",
            "ami_description" : "Amazon Linux Image with Jenkins Server",
            "run_tags" : {
                "Name" : "packer-builder"
            }
        }
    ],
    "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 }}'"
        }
    ]
}

CodePudding user response:

Adding the following command line to setup.sh solved the issue:

amazon-linux-extras install java-openjdk11 -y

It appears, that java-11-openjdk packages are not available in the Amazon Linux 2 main repository to install.

But they are now available in the Amazon Linux 2 extras repository

  • Related