Wednesday, 23 November 2022

Build a Java Application with Jenkins in Docker

cat Dockerfile

from jenkins/jenkins:lts

USER root

RUN apt-get update -qq && apt-get install wget

RUN wget

RUN tar xzf apache-maven-3.8.6-bin.tar.gz -C /opt/

RUN ln -s /opt/apache-maven-3.8.6 /opt/maven

RUN ln -s /opt/maven/bin/mvn /usr/local/bin

RUN rm -f apache-maven-3.8.6-bin.tar.gz

ENV MAVEN_HOME /opt/maven

RUN chown -R jenkins:jenkins /opt/maven

RUN apt clean

USER jenkins

sudo docker image build -t jenkins-docker .

 sudo docker images

REPOSITORY        TAG       IMAGE ID       CREATED          SIZE

jenkins-docker    latest    ca1cb1129c7e   38 seconds ago   505MB

jenkins/jenkins   lts       25fa92c47840   8 days ago       463MB

sudo docker run -it -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --restart unless-stopped jenkins-docker

sudo docker ps

CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS         PORTS                                                                                      NAMES

7333f25c2524   jenkins-docker   "/usr/bin/tini -- /u…"   4 minutes ago   Up 4 minutes>8080/tcp, :::8080->8080/tcp,>50000/tcp, :::50000->50000/tcp   silly_sanderson


#get the admin password

Jenkins global configurations

sudo docker exec -it 7333f25c2524 /bin/bash

jenkins@7333f25c2524:/$ mvn --version

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)

Maven home: /opt/maven

Java version:, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk

Default locale: en, platform encoding: UTF-8

OS name: "linux", version: "5.15.0-52-generic", arch: "amd64", family: "unix"

jenkins@7333f25c2524:/$ java --version

openjdk 2022-08-12

OpenJDK Runtime Environment Temurin- (build

OpenJDK 64-Bit Server VM Temurin- (build, mixed mode)

Execute shell commands in Jenkins by  Creating a Job

Example using jenkins-docker-maven-github


No comments:

Post a Comment